The Entity Framework 4 is driving me mad, This situation is:
Employee entity - many to many association - Department entity
I get employees from the EmployeeRepository and Departments from the DepartmentRepository. Each repository uses its own data context. My UI has a list of departments (from the DepartmentRepository) to select for an employee.
When a Department is selected for an Employee, it binds a Department from the DepartmentRepository data context, so when I try to save an Employee it complains with a nifty exception.
I need to keep the data context for Departments separate from the data context for Employees because Departments can be modified and calling save changes on DepartmentRepository cannot also save the Employee.
The separate data contexts works perfectly for my many to 0 or 1 association because I can just bind the Foreign Key property and not the entity instance.
The only workaround I can think of is to fix up the collection in the association by creating another DepartmentRepository with the same data context as the EmployeeRepository, and resolving the DepartmentRepository departments with the departments pulled from the DepartmentRepository with the EmployeeRepository datacontext, but this is just an awful, smelly design and an unacceptable "solution".
At this point I don't care about the code generation strategy (although POCO's would be nice), I really just need something that is going to work, and the Entity Framework 4 isn't terrible at creating the model definitions so I would like to stick with it.