Reputation: 219
I have been checking the DbContext class. It does not have an Add method. However, many examples use the Add method. I understand that it is a derived class of ObjectContext. There is an AddObject method. So are the Add and AddObject methods the same?
Upvotes: 0
Views: 260
Reputation: 125620
I guess Add
method you're talking about is method on DbSet<TEntity>
, and what you really see is something like that:
using(var ctx = new MyContext())
{
ctx.Users.Add(newUser);
ctx.SaveChanges();
}
It adds new item into given table, represented as DbSet<TEntity>
. I've used Users
as property name, but it will be different, depending on your context (most likely there will be more than one DbSet<TEntity>
within your context).
Upvotes: 3