开发者

Fluent Nhibernate 3 Mapping Composite Field (Custom Type)

开发者 https://www.devze.com 2023-03-09 04:40 出处:网络
HI all, my scenario public class Permission { public virtual Function Function { get; set; } public virtual Profile Profile { get; set; }

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);
    }
}


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");

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消