We use FluentNHibernate, and we encountered a problem when our object model requires data from two tables:
public class MyModel
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual int FooId { get; set; }
public virtual string FooName { get; set; }
}
Where there is a MyModel table that has Id, Name and FooId as a foreign key in the Foo table. Foo tables contain Id and FooName.
This problem is very similar to another entry here: Nhibernate: join tables and get one column from another table , but I'm trying to figure out how to do this using FluentNHibernate.
I can do Id, Name and FooId very easily .. but displaying FooName I have problems. This is my class map:
public class MyModelClassMap : ClassMap<MyModel>
{
public MyModelClassMap()
{
this.Id(a => a.Id).Column("AccountId").GeneratedBy.Identity();
this.Map(a => a.Name);
this.Map(a => a.FooId);
this.Join("Foo", join => join.KeyColumn("FooId").Map(a => a.FooName));
}
}
with this mapping, I get this error:
'class' 'urn: nhibernate-mapping-2.2' 'join' 'urn: nhibernate-mapping-2.2'. : "join-subclass, loader, sql-insert, sql-update, sql-delete, filter, resultset, query, sql-query" "urn: nhibernate-mapping-2.2".
?