2

我有这个对象:

class Person { Int32 id; String name; /*..*/ Adress adress; }
class Employee : Person { String e_g_Tax; /*..*/ Guid relationshipToManagmentId; }

以及以下映射前提:
(a) “relationshipToManagmentId”应该是外键。
(b) 表“RelationshipToManagment”是非映射表,(应用程序的旧部分)
(c) 映射策略是 TPT。(至少对于新对象:-)

映射,直到现在:

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!!

我怎么写这个?

4

1 回答 1

0

Join()只能在主键(属性 ID)上连接到另一个表,但您需要在外键列上连接。一个普通的参考做你想要的

class Employee : Person
{
    Management Management;
}

public EmployeeMap()
{
    References(x => x.Management).Column("relationshipToManagmentId");
}

更新:如果您需要表格中的只读信息,RelationshipToManagment您可以使用公式属性

public EmployeeMap()
{
    Map(x => x.RelationshipToManagment).Formula("(SELECT m.Title FROM RelationshipToManagment m WHERE m.Id = relationshipToManagmentId)");
}
于 2012-05-25T06:48:30.697 回答