I want to delete a table row that is split on two entities.
If I try to delete the main entity, I get an error if before I don\'t load the related other entity using
The best way to do this is by using a stub entity: an entity object that's only got an Id value:
var product = context.Products.First();
var photo = new ProductPhoto { ProductId = product.ProductId }; // Stub
context.Entry(photo).State = System.Data.Entity.EntityState.Deleted;
context.Products.Remove(product);
context.SaveChanges();
If you know a Product's Id you can even delete both the Product and its ProductPhoto by only creating two stubs.