Fluent NHibernate HasMany Foreign Key Mapping Problem

后端 未结 3 1047
终归单人心
终归单人心 2021-02-06 04:20

I\'m trying to map a simple data structure in nhibernate

Tables:

Employees
employeeID int
username varchar(30)
departmentID int

Departm         


        
相关标签:
3条回答
  • 2021-02-06 04:42

    You need to specify the key column.

    HasMany(m => m.Employees).KeyColumn("DepartmentId");
    
    0 讨论(0)
  • 2021-02-06 04:43

    You need to use the KeyColumn method on the HasMany declaration, as explained in the documentation

    0 讨论(0)
  • 2021-02-06 04:56

    You may either: create a Fluent NHibernate convention so that the HasMany "foreign key" is created as <'Name'>ID.

    Or change the Department mapping:

     HasMany(m => m.Employees).KeyColumns.Add("DepartmentID")
    
    0 讨论(0)
提交回复
热议问题