1
votes

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?"

2

2 Answers

1
votes

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.

1
votes

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();
}