Entity Framework Generic Repository

后端 未结 2 1459
猫巷女王i
猫巷女王i 2021-01-03 11:42

I am writing a generic repository to be used for my every model CRUD operation using entity framework CTP5 as following:

  public class BaseRepository

        
2条回答
  •  醉梦人生
    2021-01-03 12:38

    You can use CurrentValues.SetValues:

    public void Update(TEntity entity)
    {
        TEntity status = Context.Set().Find(entity.Id);
        Context.Entry(status).CurrentValues.SetValues(entity);
        Context.SaveChanges();
    }
    

    It updates scalar and complex properties but not navigation properties.

提交回复
热议问题