so I am implementing EF in my project. In my unit testing I have come accross an issue I cannot seem to figure out on my own...
I have...
class Employee{
Guid uid
name: "Foo";
Department: dempartmentObj;
}
class department{
Guid uid
name: "food prep";
desc: "preps food";
}
now as part of the logic from the program I am creating a new employee and linking them into the new department
so I
var x = new employee();
x.department = context.get(uid); //ef context call to retrieve a department
then use upsert logic to save int he event the code is used to modify instead of add
context.Entry(x).state = x.uid == guid.empty ?
EntityState.Added: EntityState.Modified;
if(x.uid == Guid.Empty)
x.uid = Guid.newGuid();
context.SaveChanges();
with unit testing I have confirmed that it works when Creating both new employee and department
however when retrieving the innner object I run into primary key violations trying to save the new employee...