首页 文章

Nhibernate按代码映射,无法确定属性的类型

提问于
浏览
0

我有实体对象 User 和值对象 Profile .

public class User : Entity<Guid>
{
    ...
    public virtual Profile Profile { get; set; }
}

public class Profile
{
    ...
    public virtual User User { get; set; }
}

我'm using nhibernate mapping by code and I' m将 UserMap.cs 中的配置文件值对象映射为 Component(c => c.Profile, ProfileMap.Mapping()); 之类的组件

ProfileMap.cs

public class ProfileMap
{
    public static Action<IComponentMapper<Profile>> Mapping()
    {
        return c =>
        {
           ...
           c.Property(p => p.User);               
        }
    }
}

在单元映射测试中,我收到内部异常消息的错误

“无法确定类型:MyApp.Domain.Model.User,MyApp.Domain,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null,对于列:NHibernate.Mapping.Column(User)”}

附:当我从 ProfileMap 注释出 User 属性并在 UserMap 映射中保留 Profile 属性时 .

1 回答

  • 1

    用户很可能不是属性,而是关系类型(多对多,或多对一或其他) . 最有可能的是它是父组件 .

    public static Action<IComponentMapper<Profile>> Mapping()
    {
        return c =>
        {
           ...
           c.Parent(p => p.User);               
        }
    }
    

相关问题