What is the difference between context.Add (Entity) and context.Entities.Add (Entity)?

I am using Entity Framework and I just want to understand the difference between context.Add(Entity)and context.Entities.Add(Entity).

+4
source share
1 answer

Both of the above do the same.

context.Add(Entity)accepts an object type, so that any type of entity that is part of the model can be transferred. This is useful if you get an object to add, but don’t know what type it will be.

context.Entities.Add(Entity)defined in DbSet, so the parameter must be of type Entityor derived type.

+3
source

Source: https://habr.com/ru/post/1695300/


All Articles