I have the this objects:
class Person { Int32 id; String name; /*..*/ Adress adress; }
class Employee : Person { String e_g_Tax; /*..*/ Guid relationshipToManagmentId; }
And the follow premises for mapping:
(a) The “relationshipToManagmentId” should be a foreign key.
(b) The table “RelationshipToManagment” is a non-mapped table, (a old part of application)
(c) The mapping strategie is TPT. (at least for new objects 🙂
Mapping, until now:
public class PersonMap : ClassMap<Person> {
public PersonMap(){
Id(x => x.id);
Map (x => x.Nachname).Length(255).Not.Nullable();
/*..*/
References(x => x.Adresse).Class(typeof(Adresse)).Not.Nullable();
}
}
public class EmployeeMap : SubclassMap<Employee>
{
public EmployeeMap()
{
Map(x => x.e_g_Tax, "enjoytax")
.Not.Nullable();
/*..*/
Join("RelationshipToManagment", xJoin =>
{
//xJoin.Table("RelationshipToManagment");
xJoin.Fetch.Join();
xJoin.KeyColumn("ID");
xJoin.Map(x => x.relationshipToManagmentId)
.Not.Nullable() ;
}); // --> exception!!
How can i write this?
Join()can only join on the primary key (property id) to the other table but you need to join on a foreign key column. A normal Reference does what you wantUpdate: if you need readonly information from the
RelationshipToManagmenttable you could use a formula property