Fluent NHibernate - Map 2 tables to one class

后端 未结 4 1954
花落未央
花落未央 2020-12-17 21:23

I have a table structure something like this

table Employees
 EmployeeID
 EmployeeLogin
 EmployeeCustID

table Customers
 CustomerID
 CustomerName

4条回答
  •  自闭症患者
    2020-12-17 21:40

    I agree with Frans above but if you're stuck with someone else's code and have to use the existing structure, you can can use WithTable.

    public class EmployeesMap : ClassMap
    {
        public EmployeesMap()
        {
            Id(x => x.EmployeeId);
            Map(x => x.EmployeeLogin);
    
            WithTable("Customers", join =>
                {
                    join.Map(m => m.EmployeeName, "CustomerName");
                    join.WithKeyColumn("EmployeeCustID");
                });
        }
    }
    
    [DataContract(IsReference = true)]
    public class Employees
    {
        [DataMember]
        public virtual int EmployeeId { get; set; }
    
        [DataMember]
        public virtual string EmployeeLogin { get; set; }
    
        [DataMember]
        public virtual string EmployeeName { get; set; }
    }
    

提交回复
热议问题