首页 > 其他分享 >EFCore 6级联删除问题解决Database operation expected to affect 1 row(s) but actually affected 0 row(s)

EFCore 6级联删除问题解决Database operation expected to affect 1 row(s) but actually affected 0 row(s)

时间:2022-09-20 00:00:44浏览次数:129  
标签:affected Database actually expected query operation row

异常信息:

Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.

处理方案:

public async Task DeleteAnimalInfo(string animalToken)
        {
            var dbContext = new DBContext(_configuration);
            var _animalInfoRepository = new EFRepository<AnimalInfo>(dbContext);
            var query = _animalInfoRepository .Table;
            query = query.Where(x => x.AnimalToken.Equals(animalToken));
            if (query.Count() <= 0)
            {
                throw new Exception("does not exist in the database");
            }
            var entity = query.FirstOrDefault();

            _animalInfoRepository .Delete(query);

        }
View Code

 

标签:affected,Database,actually,expected,query,operation,row
From: https://www.cnblogs.com/donchen/p/16709622.html

相关文章