我在流利的Nhibernate中跟随Bruno的优秀article 进行一对一的映射。但是,在映射私有实体时出现了一个小麻烦,但是错误并不明确。这是我的实体,映射和错误:
实体
public class Student
{
public virtual String Studentid { get; set; }
public virtual Address Address { get; set; }
}
public class Address
{
private String StudentId { get; set; }
private Student Student { get; set; }
public Address(Student student)
{ Student = student; }
}
映射:
public StudentMap()
{
Id(x => x.Studentid).GeneratedBy.Assigned();
HasOne(x => x.Address).Cascade.All();
}
public AddressMap()
{
Id(x=> Reveal.Member<Address>("StudentId"))
.GeneratedBy.Foreign("Student");
HasOne( x=> Reveal.Member<Address,Student>("Student"))
.Constrained()
.ForeignKey();
}
现在,当我试图运行它时,它会给出错误:
无法确定类型:System.Linq.Expressions.Expression
1[[System.Func
2 [[CastleTest.Domain.Address,CastleTest,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null],[System。 Object,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]],System.Core,Version = 3.5.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]],System.Core,Version = 3.5.0.0, Culture = neutral,PublicKeyToken = b77a5c561934e089,用于列:NHibernate.Mapping.Column(Member)
为什么会发生这种错误?
答案 0 :(得分:2)
变化
HasOne(x => Reveal.Member<Address,Student>("Student"))
到
HasOne(Reveal.Member<Address,Student>("Student"))
因为FNH认为x => Reveal.Member
是x => x.Member
来电Reveal.Member<Address,Student>("Student")
会返回adress => adress.Student