Skip to content

Commit

Permalink
fix: Ensure projected entities are not tracked
Browse files Browse the repository at this point in the history
  • Loading branch information
vyruz1986 committed Oct 13, 2023
1 parent a5b121d commit 34658f4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions Queries/BankAccounts/GetBankAccountById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public GetBankAccountByIdHandler(IMapper mapper, HaSpManContext context)

public Task<BankAccountDetail> Handle(GetBankAccountByIdQuery request, CancellationToken cancellationToken)
=> _context.BankAccounts
.AsNoTracking()
.Where(b => b.Id == request.Id)
.ProjectTo<BankAccountDetail>(_mapper.ConfigurationProvider)
.SingleAsync(cancellationToken);
Expand Down
1 change: 1 addition & 0 deletions Queries/BankAccounts/SearchBankAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public async Task<Paginated<BankAccountDetailWithTotal>> Handle(SearchBankAccoun
bankAccountsQueryable = GetOrderedQueryable(request, bankAccountsQueryable);

var bankAccountsDetailQueryable = bankAccountsQueryable
.AsNoTracking()
.ProjectTo<BankAccountDetailWithTotal>(_mapper.ConfigurationProvider)
.Skip(request.PageIndex * request.PageSize)
.Take(request.PageSize);
Expand Down
1 change: 1 addition & 0 deletions Queries/FinancialYears/GetFinancialYearsQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public async Task<IReadOnlyList<FinancialYear>> Handle(GetFinancialYearsQuery re
CancellationToken cancellationToken)
{
return await _context.FinancialYears
.AsNoTracking()
.OrderByDescending(x => x.StartDate)
.Select(x => new FinancialYear(x.Id, x.StartDate, x.EndDate, x.IsClosed, x.Name))
.ToListAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public async Task<AutocompleteCounterpartyResponse> Handle(AutocompleteCounterpa
if (request.IsMemberSearch)
{
var members = await _context.Members
.AsNoTracking()
.Where(x =>
x.FirstName.ToLower().Contains(request.SearchString.ToLower()) ||
x.LastName.ToLower().Contains(request.SearchString.ToLower()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public GetMemberByIdHandler(IMapper mapper, HaSpManContext context)

public Task<MemberDetail> Handle(GetMemberByIdQuery request, CancellationToken cancellationToken)
=> _context.Members
.AsNoTracking()
.Where(m => m.Id == request.Id)
.ProjectTo<MemberDetail>(_mapper.ConfigurationProvider)
.SingleAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task<Paginated<MemberSummary>> Handle(SearchMembersQuery request, C
var orderedQueryable = GetOrderedQueryable(request, memberQueryable);

var memberSummaryQueryable = orderedQueryable
.AsNoTracking()
.Select(x => new MemberSummary(x.Id, x.Name, x.Address.ToString(), x.Email!, x.PhoneNumber!, x.IsActive(), x.MembershipExpiryDate))
.Skip(request.PageIndex * request.PageSize)
.Take(request.PageSize);
Expand Down
1 change: 1 addition & 0 deletions Queries/Transactions/Handlers/GetTransactionByIdHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public GetTransactionByIdHandler(HaSpManContext dbContext, IMapper mapper)
}
public Task<TransactionDetail> Handle(GetTransactionByIdQuery request, CancellationToken cancellationToken)
=> _dbContext.FinancialYears
.AsNoTracking()
.SelectMany(x => x.Transactions)
.Where(x => x.Id == request.Id)
.ProjectTo<TransactionDetail>(_mapper.ConfigurationProvider)
Expand Down
1 change: 1 addition & 0 deletions Queries/Transactions/Handlers/GetTransactionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task<Paginated<TransactionSummary>> Handle(GetTransactionQuery requ
var transactions = GetOrderedQueryable(request, baseQuery);

var transactionViewModels = transactions
.AsNoTracking()
.ProjectTo<TransactionSummary>(_mapper.ConfigurationProvider)
.Skip(request.PageIndex * request.PageSize)
.Take(request.PageSize);
Expand Down

0 comments on commit 34658f4

Please sign in to comment.