Reputation: 417
Can anyone help with this?
public virtual void AddOrUpdate(T entity)
{
#region Argument Validation
if (entity == null)
{
throw new ArgumentNullException("entity");
}
#endregion
DbSet.AddOrUpdate(e => e.Id, entity);
SaveChanges();
}
Getting error as "DbSet does not contain a definition for AddorUpdate?"
Upvotes: 2
Views: 1873
Reputation: 417
We have an alternate way to solve this.
public virtual void AddOrUpdate(T entity)
{ if (entity == null)
throw new ArgumentNullException("entity");
this.DbContext.Update(entity);
this.DbContext.SaveChanges();
}
Upvotes: 3
Reputation: 588
Method AddOrUpdate does not exist in Entity Framework Core. There are some issues on ef core github about it:
Merge/Upsert/AddOrUpdate support
Another issue that has information that it will be added in the future.
Upvotes: 1