admin管理员组文章数量:1391925
I am trying to use TransactionScope
to make my db context operations spread across different files run under one transaction, so all or none save should happen.
The problem is it is giving me this error even before the saving of entities start. It gives me the error when I just try to fetch data using the db context
Cannot enlist in the transaction because a local transaction is in progress on the connection. Finish local transaction and retry.
This is my code
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
// this first line itself is giving me the error even when I am just trying to select data here and
// have not even started saving anything to the database
IEnumerable<FormHierarchy> formHierarchies = await _unitOfWork.FormHierarchyRepository.GetAllowedFormHierarchiesForADeclarationTypeAsync(model.DeclarationType);
// A lot of code for saving the entities follows this
}
This is the repository method for selecting data
public class FormHierarchyRepository : Repository<FormHierarchy>, IFormHierarchyRepository
{
private readonly IDapperQueryManager _queryManager;
public readonly PJDbContext _dbContext;
public FormHierarchyRepository(IDapperQueryManager queryManager, PJDbContext dbContext) : base(dbContext)
{
_dbContext = dbContext;
_queryManager = queryManager;
}
public async Task<IEnumerable<FormHierarchy>> GetAllowedFormHierarchiesForADeclarationTypeAsync(DeclarationTypes declarationType)
{
return await _dbContext.FormHierarchy.Where(x => x.DeclarationTypeId == (int)declarationType).ToListAsync();
}
}
If this error would have come when I would have started saving the entities I would have understood it and would have tried to adjust some code following these type of posts
But it is coming on the data selection which ideally should not be even using the transaction in that sense.
Any idea what could be going wrong and what should I try?
本文标签:
版权声明:本文标题:c# - Cannot enlist in the transaction because a local transaction is in progress on the connection. Finish local transaction and 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744669492a2618739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论