EF Core:必须是可还原节点

时间:2019-08-27 08:59:09

标签: c# linq .net-core entity-framework-core

我收到“必须是可还原节点”错误。我相信这是一个错误,但是我无法解决它。

我是DotNet Core的最新稳定版本,并使用Microsoft.EntityFrameworkCore 2.2.6。另外,我正在使用Devart.DAta.Oracle.EFCore v9.7.805。

"//"

更新

NumberOfPeriods为5

StackTrace:

public async Task<DomainResult<IEnumerable<InternalRiskDto>>> GetRiskByPeriod(int customerNumber, bool resultForGuarantor, int numberofPeriod, CancellationToken ctx = default)
{
    Expression<Func<InternalRiscData, InternalRiskDto>> selectorExpression = r => new InternalRiskDto
    {
        A12 = r.IrdA12 ?? 0,
        A1224 = r.IrdA1224 ?? 0,
        A24 = r.IrdA24 ?? 0,
        AccNo = r.IrdAccNo,
        Branch = r.IrdBranch,
        Fincode = r.IrdFincode,
        Frees = r.IrdFrees,
        Ftahak = r.IrdFtahak,
        Idno = r.IrdIdno,
        Limit = r.IrdLimit < r.IrdA12 + r.IrdA1224 + r.IrdA24 ? r.IrdA12 + r.IrdA1224 + r.IrdA24 : r.IrdLimit,
        Crmno = resultForGuarantor ? r.IrdKcrmno : r.IrdMcrmno,
        Risccode = r.IrdRisccode,
        Riscdate = r.IrdRiscdate,
        Riscode2 = r.IrdRiscode2,
        Rowid = r.IrdRowid
    };

    Expression<Func<InternalRiscData, bool>> crmPredicate = x => ((resultForGuarantor && x.IrdKcrmno == customerNumber) || (!resultForGuarantor && x.IrdMcrmno == customerNumber));

    var dateQueryable = _riskRepository.GetQueryable()
        .Where(crmPredicate)
        .Select(x => x.IrdRiscdate)
        .Distinct()
        .OrderByDescending(x => x)
        .Take(numberofPeriod);

    var dateList = await dateQueryable.ToListAsync(ctx);

    if (!dateList.Any())
        return _errorDescriber.NoRiskRecordFound(customerNumber, numberofPeriod);

    var result = _riskRepository.GetQueryable()
        .Where(crmPredicate)
        .Where(ris => dateQueryable.Any(x => ris.IrdRiscdate == x)) //Problem arises here
        .Select(selectorExpression)
        .Distinct()
        .OrderByDescending(x => x.Riscdate).ThenBy(x => x.Risccode);

    return DomainResult<IEnumerable<InternalRiskDto>>.Success(await result.ToListAsync(ctx));
}

1 个答案:

答案 0 :(得分:1)

Any代替Contains对我有用。似乎Any不能作为数据库查询来评估,因此EF Core尝试在本地对其进行评估,但由于EF Core中的错误而导致错误。

var result = _riskRepository.GetQueryable()
    ...
    .Where(ris => dateQueryable.Any(x => ris.IrdRiscdate == x)) //Problem arises here
    ...;

替换为

var result = _riskRepository.GetQueryable()
    ...
    .Where(ris => dateList.Contains(ris.Riscdate))
    ...;

记录:此错误将在EF Core 3.0版中修复

特别感谢@IvanStoev