public record struct ImposterDbContextAuthorization(int AccountUserId, bool HasPermissionCanAccessAnyAccount, bool HasPermissionSuperUser = false) : IDbContextAuthorization;
< /code>
public async Task Send(int clinicId)
{
// added await here
Task.Run(async () =>
{
await SendIt(clinicId, DbContext.GetAccountId());
});
return "";
}
public async Task SendIt(int clinicId, int accountId)
{
var scope = _serviceScopeFactory.CreateScope();
var dbOptions = scope.ServiceProvider.GetRequiredService();
var imposter = new ImposterDbContextAuthorization(accountId, true);
var dbContext = new MyDbContext(dbOptions, imposter);
var allRecords = await dbContext.Set()
.AsNoTracking()
.Where(visit => visit.ClinicId == clinicId)
.GroupBy(visit => visit.PatientId)
.Select(group => group.Key).ToListAsync();
// !!! allRecords.Count is 0, even though "SELECT * FROM visit WHERE clinic_id = clinicId" returns 1 record in database
return "";
}
< /code>
I tried adding await to the Task.Run
SQL: -- @__ef_filter__IncludeDeleted_0='False'
12:10:30:610 -- @__ef_filter___hasPermissionCanAccessAnyAccount_4='True'
12:10:30:610 -- @__ef_filter__p_3='True'
12:10:30:610 -- @__ef_filter___accountId_1='759' (Nullable = true)
12:10:30:610 -- @__ef_filter___accountUserId_2='860'
12:10:30:610 -- @__clinicId_0='1696'
12:10:30:610 SELECT v.patient_id
12:10:30:610 FROM visit AS v
12:10:30:610 WHERE v.discriminator = 'Visit' AND (@__ef_filter__IncludeDeleted_0 OR NOT (v.is_deleted)) AND (@__ef_filter___hasPermissionCanAccessAnyAccount_4 OR CASE
12:10:30:610 WHEN @__ef_filter__p_3 THEN v.account_id = @__ef_filter___accountId_1
12:10:30:610 ELSE EXISTS (
12:10:30:610 SELECT 1
12:10:30:610 FROM account_user AS a
12:10:30:610 WHERE a.id = @__ef_filter___accountUserId_2 AND a.account_id = v.account_id)
12:10:30:610 END) AND v.clinic_id = @__clinicId_0
12:10:30:610 GROUP BY v.patient_id {SourceContext="UrgentIQ.Services.Controller.Payment.PaymentService", ActionId="c34bc56c-bc7a-48ec-b921-fdbb02f31129", ActionName="UrgentIQ.WebApi.Controllers.Payment.PaymentController.AuthviaTxt (UrgentIQ.WebApi)", RequestId="0HNABH0DT8O89", RequestPath="/api/Payment/AuthviaTxt/1696", ThreadName=".NET TP Worker"}
12:10:30:610 2
< /code>
Above was found with allRecords.ToQueryString()
. Я думаю, может быть, ошибка из -за account_id несоответствует
Почему AllRecords возвращается с нулевыми записями, когда в базе данных есть записи? < /p> [code]public record struct ImposterDbContextAuthorization(int AccountUserId, bool HasPermissionCanAccessAnyAccount, bool HasPermissionSuperUser = false) : IDbContextAuthorization; < /code> public async Task Send(int clinicId) { // added await here Task.Run(async () => { await SendIt(clinicId, DbContext.GetAccountId()); }); return ""; } public async Task SendIt(int clinicId, int accountId) { var scope = _serviceScopeFactory.CreateScope(); var dbOptions = scope.ServiceProvider.GetRequiredService(); var imposter = new ImposterDbContextAuthorization(accountId, true); var dbContext = new MyDbContext(dbOptions, imposter);
var allRecords = await dbContext.Set() .AsNoTracking() .Where(visit => visit.ClinicId == clinicId) .GroupBy(visit => visit.PatientId) .Select(group => group.Key).ToListAsync(); // !!! allRecords.Count is 0, even though "SELECT * FROM visit WHERE clinic_id = clinicId" returns 1 record in database return ""; } < /code> I tried adding await to the Task.Run[/code], сделано записи return sql из AllRecords : [code]SQL: -- @__ef_filter__IncludeDeleted_0='False' 12:10:30:610 -- @__ef_filter___hasPermissionCanAccessAnyAccount_4='True' 12:10:30:610 -- @__ef_filter__p_3='True' 12:10:30:610 -- @__ef_filter___accountId_1='759' (Nullable = true) 12:10:30:610 -- @__ef_filter___accountUserId_2='860' 12:10:30:610 -- @__clinicId_0='1696' 12:10:30:610 SELECT v.patient_id 12:10:30:610 FROM visit AS v 12:10:30:610 WHERE v.discriminator = 'Visit' AND (@__ef_filter__IncludeDeleted_0 OR NOT (v.is_deleted)) AND (@__ef_filter___hasPermissionCanAccessAnyAccount_4 OR CASE 12:10:30:610 WHEN @__ef_filter__p_3 THEN v.account_id = @__ef_filter___accountId_1 12:10:30:610 ELSE EXISTS ( 12:10:30:610 SELECT 1 12:10:30:610 FROM account_user AS a 12:10:30:610 WHERE a.id = @__ef_filter___accountUserId_2 AND a.account_id = v.account_id) 12:10:30:610 END) AND v.clinic_id = @__clinicId_0 12:10:30:610 GROUP BY v.patient_id {SourceContext="UrgentIQ.Services.Controller.Payment.PaymentService", ActionId="c34bc56c-bc7a-48ec-b921-fdbb02f31129", ActionName="UrgentIQ.WebApi.Controllers.Payment.PaymentController.AuthviaTxt (UrgentIQ.WebApi)", RequestId="0HNABH0DT8O89", RequestPath="/api/Payment/AuthviaTxt/1696", ThreadName=".NET TP Worker"} 12:10:30:610 2 < /code> Above was found with allRecords.ToQueryString()[/code]. Я думаю, может быть, ошибка из -за account_id несоответствует