Can anyone tell me the correct way to store entities in this situation: A department has many member employees and one employee as a head. So:
CREATE TABLE dbo.Department (
DepartmentId int NOT NULL ,
HeadedByEmployeeId int NOT NULL ,
DepartmentName varchar (50) NOT NULL
)
CREATE TABLE dbo.Employee (
EmployeeId int NOT NULL ,
MemberOfDepartmentId int NOT NULL ,
FirstName varchar (50) NOT NULL ,
LastName varchar (50) NOT NULL
)
Where HeadedByEmployeeId is a foreign key on EmployeeId, and MemberOfDepartmentId on DepartmentId.
LLBLGen fields mapped on relations are renamed as follows:
Department
Head (Department – Employee (m:1))
Member (Department – Employee (1:n))
Employee
DepartmentHeaded (Employee – Department(1:n))
Department (Employee – Department (m:1))
And finally in the code we wish to add a new department with a new member employee who is also its head:
DepartmentEntity department = new DepartmentEntity();
department.Name = "Accounts";
EmployeeEntity employee = new EmployeeEntity();
employee.FirstName = "Tom";
employee.LastName = "Jones";
department.Member.Add(employee);
department.Head = employee;
Now employee.Save(true) fails with ‘Cannot insert the value NULL into column 'MemberOfDepartmentId’’ and department.Save(true) fails with ‘Cannot insert the value NULL into column 'HeadedByEmployeeId'’
Is there any way this can be done without allowing one of the foreign key fields to take nulls?
Thanks, J.