通过 ef 使用存储库和工作单元更新 .net core 中的特定字段

update particular field in .net core by ef with repository and unit of work

我有存储库、服务和工作单元。

我有用户名、密码、性别和多条记录可用的用户模型。

我在一个方法中访问用户控制器模型的所有数据,然后我只想更新整个数据的密码。

那么我们该怎么做呢?

展示一些你尝试过的实现方式:

在您的 RepositoryBase 或等效项中,您可以添加如下内容:

            entityToUpdate.LastUpdated = DateTime.UtcNow;
            DbSet.Attach(entityToUpdate);
            Context.Entry(entityToUpdate).State = EntityState.Modified;
            //Beware of tracked queries
            Context.SaveChanges();