I have a 2 Entity : Person (Id, CategoryId) and Category(Id).
Now when I try to insert a new Person with only the Id and CategoryId it throws an exception about the Person having a relationship with Category.
The following code doesn't work:
Person newPerson = new Person();
newPerson.Id = 1;
newPerson.CategoryId = 1;
context.AddToPersonSet(newPerson);
context.SaveChanges
This code works
Person newPerson = new Person();
newPerson.Id = 1;
newPerson.Category = context.CategorySet.Where(cat=> cat.Id == 1).First();
newPerson.CategoryId = 1;
context.AddToPersonSet(newPerson);
context.SaveChanges
Is there another way to insert without having to fetch the Category entity ?