Fluent NHibernate - Map 2 tables to one class

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

    Is EmployeeCustID unique? If not, this is never going to work, as you then try to cram two different entity types into 1. Also, with your structure, how do you want to save an instance? -> the CustomerID isn't known, so you can't save such an entity.

    IMHO it's better to simply keep Customer as a related entity to Employee, as (I assume) the EmployeeCustID is used to link a Customer entity to an Employee entity if the employee is also a customer, which means 'customer' is just a role for employee and therefore optional and changeable and thus should be a separate entity.

提交回复
热议问题