【问题标题】:DbSet does not contain a definition for AddorUpdateDbSet 不包含 AddorUpdate 的定义
【发布时间】:2020-06-17 17:54:25
【问题描述】:

有人可以帮忙吗?

 public virtual void AddOrUpdate(T entity)
  {
    #region Argument Validation

    if (entity == null)
    {
        throw new ArgumentNullException("entity");
    }

    #endregion

    DbSet.AddOrUpdate(e => e.Id, entity);
    SaveChanges();

}

因为“DbSet 不包含 AddorUpdate 的定义?”而出现错误?

【问题讨论】:

    标签: asp.net-core entity-framework-core


    【解决方案1】:

    Entity Framework Core 中不存在方法 AddOrUpdate。 ef core github上有一些关于它的问题:
    Merge/Upsert/AddOrUpdate support
    Another issue that has information that it will be added in the future.

    【讨论】:

      【解决方案2】:

      我们有另一种方法来解决这个问题。

        public virtual void AddOrUpdate(T entity)
        {   if (entity == null)
          throw new ArgumentNullException("entity");
      
       this.DbContext.Update(entity);  
       this.DbContext.SaveChanges();
      }
      

      【讨论】:

        猜你喜欢
        • 2021-07-22
        • 1970-01-01
        • 1970-01-01
        • 2011-11-17
        • 1970-01-01
        • 2023-01-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多