使用 Fluent 和 Nhibernate 进行一对一映射时的 Reveal.Member 问题

发布于 2024-12-05 22:54:53 字数 1636 浏览 0 评论 0原文

我正在关注布鲁诺的优秀 文章,用于流畅的 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.Expression1[[System.Func2[[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.Expression1[[System.Func2[[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 技术交流群。

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

发布评论

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

评论(1

凉世弥音 2024-12-12 22:54:53

更改

HasOne(x => Reveal.Member<Address,Student>("Student"))

HasOne(Reveal.Member<Address,Student>("Student"))

因为 FNH 认为 x => Reveal.Member 是 x => x.Member

调用 Reveal.Member

("Student")
返回类似于 adress =>;地址.学生

change

HasOne(x => Reveal.Member<Address,Student>("Student"))

to

HasOne(Reveal.Member<Address,Student>("Student"))

because FNH thinks x => Reveal.Member is x => x.Member

the call Reveal.Member<Address,Student>("Student") returns something like adress => adress.Student

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