I am trying to update a project and use the assembly in the encoder.
I have 2 objects:
public class Person { public virtual int Id { get; set; } public virtual User User { get; set; } } public class User { public virtual int Id { get; set; } public virtual User Person { get; set; } }
The structure of the database is as follows:
table: users, fields: id table: people, fields: id, userId
With FluentNHibernate, I could map this as follows:
public class UserMap : ClassMap<User> { public UserMap() { Id(x => x.Id).GeneratedBy.Identity(); HasOne(x => x.Person).PropertyRef("User").Not.LazyLoad(); } } public class PersonMap : ClassMap<Person> { public PersonMap() { Id(x => x.Id).GeneratedBy.Identity(); References(x => x.User).Column("UserId").Not.Nullable().Not.LazyLoad(); } }
But you canβt get it to work with NH 3.2 in the code collector. This is what I have done so far.
OneToOne(x=>x.Person, m => { m.PropertyReference(typeof(Person).GetProperty("User")); }); OneToOne(x=>x.User, m => {});
Now the relationship maps to User.Id and Person.Id, but personid and userid may be different. It is also possible that the user does not have a person.
from Users user0_ left outer join People person1_ on user0_.Id=person1_.Id
I think I need to indicate that Person β User maps to the UserId column, but how ?.
source share