Fluent NHibernate - Map 2 tables to one class

后端 未结 4 1973
花落未央
花落未央 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:49

    I have not tried this since Fluent NHibernate went to 1.0 so my syntax may be incorrect. I'm pretty sure this will only work if Customer.CustomerId is a foreign key to Employee.

    public class EmployeeMap : ClassMap
    {
      public EmployeeMap()
      {
        Id(x => x.EmployeeId);
        Map(x => x.EmployeeLogin);
    
        Table("Customer", m =>
        {
          m.Map(x => x.EmployeeName, "CustomerName");
        });
      }
    }
    

提交回复
热议问题