Fluent Nhibernate 3 映射复合字段(自定义类型)

发布于 2024-11-10 18:43:04 字数 1063 浏览 7 评论 0原文

大家好,我的场景

public class Permission
{
    public virtual Function Function { get; set; }
    public virtual Profile Profile { get; set; }
}

public class MapPermission : ClassMap<Permission>
{
    public MapPermission()
    {
        Table("Permissions".ToUpper());
        CompositeId().KeyProperty(x => x.Function, "FunctionID").KeyProperty(x => x.Profile, "ProfileID");

    }
}

是,功能和配置文件是两个简单映射的实体。当我运行时出现此错误:

无法确定类型:Data.Model.Entities.Function、Data.Model、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null,对于列:NHibernate.Mapping.Column(FunctionID )"}

有没有办法避免这种情况?最终我需要创建一个具有由两个自定义映射类组成的 CompositeID 的类。如果我使用带有 int 字段的 compositeID ,它会像一个魅力一样工作,

感谢高级

函数(如配置文件)映射

public class Function
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
}

public class MapFunction : ClassMap<Function>
{
    public MapFunction()
    {
        Table("FUNCTIONS");
        Id(x => x.ID);
        Map(x => x.Name);
    }
}

HI all, my scenario

public class Permission
{
    public virtual Function Function { get; set; }
    public virtual Profile Profile { get; set; }
}

public class MapPermission : ClassMap<Permission>
{
    public MapPermission()
    {
        Table("Permissions".ToUpper());
        CompositeId().KeyProperty(x => x.Function, "FunctionID").KeyProperty(x => x.Profile, "ProfileID");

    }
}

Where Function AND Profile are two easy mapped entities. When i Run i have this error:

Could not determine type for: Data.Model.Entities.Function, Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(FunctionID)"}

Is there a way to avoid this? ultimately i need to create a class with CompositeID made by two custom mapped classes. If i uses compositeID with int fields it works like a charm

Thanks in Advance

Function (Like Profile) Mapping

public class Function
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
}

public class MapFunction : ClassMap<Function>
{
    public MapFunction()
    {
        Table("FUNCTIONS");
        Id(x => x.ID);
        Map(x => x.Name);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2024-11-17 18:43:04

使用KeyReference代替KeyProperty

public class MapPermission : ClassMap<Permission>
{
    public MapPermission()
    {
        Table("Permissions".ToUpper());
        CompositeId()
            .KeyReference(x => x.Function, "FunctionID")
            .KeyReference(x => x.Profile, "ProfileID");

    }
}

Use KeyReference instead of KeyProperty

public class MapPermission : ClassMap<Permission>
{
    public MapPermission()
    {
        Table("Permissions".ToUpper());
        CompositeId()
            .KeyReference(x => x.Function, "FunctionID")
            .KeyReference(x => x.Profile, "ProfileID");

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文