2
votes

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?

1

1 Answers

2
votes

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