我在我的LINQ代码上收到此错误
Client projection contains reference to constant expression of through instance method
This could potentially cause memory leak. Consider making the method static so that it does not capture constant in the instance
histories = await _resourceContext.Histories
.AsNoTracking()
.Where(x => x.LmoId == request.LmoId)
.OrderByDescending(x => x.DateCreated)
.Skip(fromPage).Take(request.PageSize)
.Select(x => new HistoryDto
{
Id = x.Id,
DateCreated = x.DateCreated.ToString(),
CreatorName = GetAdvisorFullName(x.CreatedBy, cancellationToken)
})
.ToListAsync(cancellationToken);
private string GetAdvisorFullName(long advisorId, CancellationToken cancellationToken)
{
var advisorDetails = _mediator.Send(new GetAdvisorQuery(advisorId), cancellationToken);
string fullName = $"{advisorDetails.Result.FirstName} {advisorDetails.Result.LastName}";
return fullName;
}
我试过了
-
通过在查询中直接调用上下文,这是不允许的,因为在一个调用中不允许两个上下文
-
首先将其转换为可查询的,然后列出
-
使Get方法异步
-
如果我将此方法设为静态方法,则中介调用会出现错误