我在OData控制器中编写了一个方法,用于从数据库中获取我的所有实体数据并将其加载到网格中,如果我使用任何字符串进行过滤,则它将使用过滤器属性/数据调用相同的方法,因为我们使用了如下所示的“ OData-EnabledQuery”注释,
[HttpGet]
[EnableQuery, ODataRoute("AccountCodeAuditLogs")]
public async Task<IQueryable<AccountCodeEntityChangeAudit>> GetAccountCodeAuditLogsAsync(CancellationToken cancellationToken, [FromODataUri] long languageId = default(long))
{
try
{
return await _accountCodesService.GetAccountCodeAuditLogsAsync(GetAuthenticatedUser(), cancellationToken, languageId);
}
catch (Exception e)
{
throw HttpError(e);
}
}
我的服务方代码,
public async Task<IQueryable<AccountCodeEntityChangeAudit>> GetAccountCodeAuditLogsAsync(IClaimedUser user, CancellationToken cancellationToken, long languageId = default(long))
{
await HasPermissionAsync(user, EntityName.AccountCode, PermissionName.View);
cancellationToken.ThrowIfCancellationRequested();
var statusTexts = TenantBasedKeyValueStore<Dictionary<long, Dictionary<long, string>>>.GetOrAdd(Tenant, PlatformCacheConstants.AccountCodeStagingStatusCacheKey, () =>
{
return
(
from status in DataContext.StagingStatuses.Where(sts => sts.IsActive)
join statusTxt in DataContext.StagingStatusTexts.Where(st => st.IsActive) on status.StagingStatusId equals statusTxt.StagingStatusId
select statusTxt
)
.GroupBy(g => g.LanguageId)
.ToDictionary(stx => stx.Key, stx => stx.ToDictionary(d => d.StagingStatusId, d => d.Name));
});
var userPreferredlanguageId = default(long) == languageId ? GetDefaultLanguageId() : languageId;
var statusTextsForLanguage = statusTexts.ContainsKey(userPreferredlanguageId) ? statusTexts[userPreferredlanguageId] : EmptyStagingStatusTexts;
var pendingStatusTxt = statusTextsForLanguage.ContainsKey(PlatformServiceConstants.StagingStatusPending) ? statusTextsForLanguage[PlatformServiceConstants.StagingStatusPending] : null;
var rejectedStatusTxt = statusTextsForLanguage.ContainsKey(PlatformServiceConstants.StagingStatusRejected) ? statusTextsForLanguage[PlatformServiceConstants.StagingStatusRejected] : null;
var approvedStatusTxt = statusTextsForLanguage.ContainsKey(PlatformServiceConstants.StagingStatusApproved) ? statusTextsForLanguage[PlatformServiceConstants.StagingStatusApproved] : null;
var acsEntityAuditInfo = from entityAudit in DataContext.EntityAudits.Where(aud => aud.EntityName == AccountCodeEntityName).AsNoTracking()
join accountCode in DataContext.AccountCodes.AsNoTracking() on entityAudit.EntityId equals accountCode.AccountCodeId
select new AccountCodeEntityChangeAudit
{
EntityId = entityAudit.EntityId,
IsActive = true,
AuditId = entityAudit.EntityAuditId,
AccountCodeDisplay = accountCode.AccountCodeDisplay,
AccountCodeDescription = accountCode.PublishedAccount == null ? accountCode.AccountCodeDescription : accountCode.PublishedAccount.AccountCodeDescription,
Attribute = entityAudit.FieldDisplayName,
EntityField = entityAudit.Field,
ValueBefore = (string.IsNullOrEmpty(entityAudit.ValueBefore)) ? null
: entityAudit.Field.Contains("PrimaryUOMId") ? accountCode.PrimaryUOM.UOMName
: entityAudit.Field.Contains("SecondaryUOMId") ? accountCode.SecondaryUOM.UOMName
: entityAudit.Field.Contains("CurrencyId") ? accountCode.Currency.CurrencyName
: entityAudit.Field.Contains("ParentId") ? accountCode.Parent.AccountCodeDisplay
: entityAudit.Field.Contains("PublishedAccountId") ? accountCode.AccountCodeDisplay
: entityAudit.Field.Contains("StagingStatusId") ? entityAudit.ValueBefore == PlatformServiceConstants.StagingStatusPending.ToString() ? pendingStatusTxt : entityAudit.ValueBefore == PlatformServiceConstants.StagingStatusRejected.ToString() ? rejectedStatusTxt : entityAudit.ValueBefore == PlatformServiceConstants.StagingStatusApproved.ToString() ? approvedStatusTxt : null
: entityAudit.ValueBefore,
ValueAfter = (string.IsNullOrEmpty(entityAudit.ValueAfter)) ? null
: entityAudit.Field.Contains("PrimaryUOMId") ? accountCode.PrimaryUOM.UOMName
: entityAudit.Field.Contains("SecondaryUOMId") ? accountCode.SecondaryUOM.UOMName
: entityAudit.Field.Contains("CurrencyId") ? accountCode.Currency.CurrencyName
: entityAudit.Field.Contains("ParentId") ? accountCode.Parent.AccountCodeDisplay
: entityAudit.Field.Contains("PublishedAccountId") ? accountCode.AccountCodeDisplay
: entityAudit.Field.Contains("StagingStatusId") ? entityAudit.ValueAfter == PlatformServiceConstants.StagingStatusPending.ToString() ? pendingStatusTxt : entityAudit.ValueAfter == PlatformServiceConstants.StagingStatusRejected.ToString() ? rejectedStatusTxt : entityAudit.ValueAfter == PlatformServiceConstants.StagingStatusApproved.ToString() ? approvedStatusTxt : null
: entityAudit.ValueAfter,
EditType = entityAudit.EntityAuditAction.EntityAuditActionTexts.FirstOrDefault(x=>x.LanguageId == userPreferredlanguageId).Name,
ChangedDate = entityAudit.CreatedDate,
ChangedByFullName = entityAudit.ChangedBy.FullName,
Version = entityAudit.Version
};
return acsEntityAuditInfo;
}
这是我的问题,在过滤网格数据时,如果表包含数百万个数据,则返回以下给定的错误;如果表包含的数据较少,则返回过滤后的结果。因此需要增加API响应时间,否则这是OData / LINQ / Entity Framework问题,这里的确切问题是什么?我无法确定问题。谁能帮我吗?
Error: "message":"The wait operation timed out","type":"System.ComponentModel.Win32Exception","stacktrace":""