Tutorial by Examples

EntityState.Added can be set in two fully equivalent ways: By setting the state of its entry in the context: context.Entry(entity).State = EntityState.Added; By adding it to a DbSet of the context: context.Entities.Add(entity); When calling SaveChanges, the entity will be inse...
Setting the state of an object graph (a collection of related entities) to Added is different than setting a single entity as Added (see this example). In the example, we store planets and their moons: Class model public class Planet { public Planet() { Moons = new HashSet<...

Page 1 of 1