You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Customer
{
public int Id {get; set;}
public int Name {get; set;}
public virtual ICollection<CustomerCategory> Categories {get; set;}
}
public class CustomerCategory
{
public int Id {get; set;}
public int CustomerId {get; set;}
public int CategoryId{get; set;}
public virtual Customer Customer {get; set;}
public virtual Category Category {get; set;}
}
public class Category
{
public int Id {get; set;}
public int Name {get; set;}
}
The relationship mapping for the Customer is:
internal class CustomerMap : EntityTypeConfiguration<Customer>
{
public CustomerMap ()
{
this.HasMany(t => t.Categories)
.WithOptional()
.HasForeignKey(d => d.CustomerId)
.WillCascadeOnDelete();
}
}
I'm not using the default naming convention for primary and foreign keys in the database.
My DTO classes are similar to the above models but they do not contain the foreign key properties. When mapping, these are ignored by AutoMapper.
There are a few issues with GraphDiff:
When adding new categories to the customer, without the foreach loop in the Update method, GraphDiff sends insert statements where customerId and categoryId are 0. Thefore the inserts fail.
After the entity is updated, GraphDiff returns the updated customer, but the Category propery of each CustomerCategory is null.
Why is this happening? Am I missing something or is this a limitation of GraphDiff and/or EF?
The text was updated successfully, but these errors were encountered:
Hi, I think that actually this is a limitation of graphdiff due to a BUG, i will try to submit a pull request to fix this in the near future, btw you could add FK to your DTOs, this should solve the issue.
I can confirm that I have also seen this behavior where
You are saving a parent object with an OwnedCollection that is creating new child objects
The child objects on the OwnedCollection have FK references back to the parent object
The FK references from the child to the parent are not assigned values
When you attempt to save the parent, EF throws an error about the EntityKey of the child object not being valid.
As described by cryo75, the workaround is to give values to the child objects' FKs to the parent object. I've not done sufficient testing to know yet whether or not this is a bug in GraphDiff/GraphDiff's usage of EF, or a problem with EF itself.
I have this model:
The relationship mapping for the Customer is:
For adding and updating I call the same method:
NOTE:
There are a few issues with GraphDiff:
Why is this happening? Am I missing something or is this a limitation of GraphDiff and/or EF?
The text was updated successfully, but these errors were encountered: