What is the difference between IDbSet.Add and DbEntityEntry.State = EntityState.Added?
问题 In EF 4.1+, is there a difference between these 2 lines of code? dbContext.SomeEntitySet.Add(entityInstance); dbContext.Entry(entityInstance).State = EntityState.Added; Or do they do the same thing? I'm wondering if one might affect child collections / navigation properties differently than the other. 回答1: When you use dbContext.SomeEntitySet.Add(entityInstance); the status for this and all its related entities/collections is set to added, while dbContext.Entry(entityInstance).State =