使用 Fluent 和 Nhibernate 进行一对一映射时的 Reveal.Member 问题
我正在关注布鲁诺的优秀 文章,用于流畅的 Nhibernate 中的一对一映射。然而,我在映射私有实体时遇到了一个小麻烦,并出现了一个不清楚的错误。这是我的实体、映射和错误:
实体
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,版本= 2.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089]],System.Core,版本=3.5.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]],System.Core,版本=3.5.0.0,文化=中性,PublicKeyToken=b77a5c561934e089,对于列: NHibernate.Mapping.Column(成员)
为什么这个错误发生了吗?
I was following Bruno's excellent article for one-to-one mapping in fluent Nhibernate. However I ran into a small trouble while mapping the private entities with an error which is not clear. Here are my entities, mapping and error:
Entities
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; }
}
Mapping :
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();
}
Now when I am trying to run it it's giving error as:
Could not determine type for: 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, for columns: NHibernate.Mapping.Column(Member)
Why is this error happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
为
因为 FNH 认为 x => Reveal.Member 是
x => x.Member
调用
Reveal.Member("Student")
返回类似于adress =>;地址.学生
change
to
because FNH thinks
x => Reveal.Member
isx => x.Member
the call
Reveal.Member<Address,Student>("Student")
returns something likeadress => adress.Student