Ian wrote:
Hi,
'A' does have a PK and its an identity field and its marked as one in llblGen designer and it doesn't have a NEWID() default value. 'A' entities can be inserted by themself just fine and it also works when you add join table entities to an already existing A entity although, in this case, I'm manually setting the reference to A in the join table entity before adding it to the collection.
Perhaps you could post a piece of code of what you're doing, including the save call
In the situation that's not working, I examined the A entity in the debugger just before the update call. It has a pk of 0 and is set to 'IsNew'. In its collection of join row entities, the added entity has a pk of 0 and is marked as 'IsNew'.
Perhaps I'm adding the object to the collection incorrectly?
I'm just doing...
entityCollection.Add(instance);
Is that enought?
A is 'Department', B is 'Employee'. Intermediate Entity is 'DepartmentEmployee'.
DepartmentEntity d = new DepartmentEntity();
// fill in d's properties.
EmployeeEntity e = new EmployeeEntity();
// fill in e's properties.
DepartmentEmployeeEntity de = new DepartmentEmployeeEntity();
now either do:
de.Department = d;
de.Employee = e;
OR:
d.DepartmentEmployees.Add(de);
e.DepartmentEmployees.Add(de);
THEN, save the graph:
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.SaveEntity(d);