【问题标题】:Linq with EF core 2.2 Condition with where Clause FK and PKLinq with EF core 2.2 Condition with where Clause FK and PK
【发布时间】:2020-04-06 16:17:24
【问题描述】:

您好,我在使用带有 FK 和 PK 的 where 子句时遇到问题,因为来自 InstalltionÍnformation 的 FK 是一个对象。我无法理解。 i => i.ImportRunID 是一个 iqueryable 并且不能转换为 int ImportRuns.ImportRunId

var Aggnone = context.ImportRuns.Select(IR => new
                        {
                            ImportRunId = IR.ImportRunId,
                            ExtractedDate = IR.ExtractedDate,
                            ProcessDate = IR.ProcessDate,
                            ProcessResult = IR.ProcessResult,
                            FailureDescription = IR.ProcessResult,
                            InstallationInformationIDFK = context.InstallationInformation.Select(II => new
                            {
                                InstallationInformationID = II.InstallationInformationID,
                                LicenceKey = II.LicenceKey,
                                ProductVersion = II.ProductVersion,
                                ProductName = II.ProductName,
                                CompanyName = II.CompanyName,
                                Timestamp = II.Timestamp
                            })
                        }).Where(x => x.ImportRunId == context.InstallationInformation.Select(i => i.ImportRunID);

MSSQL中的等价物(应该是什么)

 Select * from ImportRuns as IR
 left join InstallationInformation as II 
 on IR.ImportRunId = II.ImportRunId

有没有办法解决这个问题?

【问题讨论】:

    标签: c# linq entity-framework-core


    【解决方案1】:

    尝试使用

    context.InstallationInformation.FirstOrDefault(i => i.ImportRunID).InstallationInformationID 
    

    而不是

    context.InstallationInformation.Select(i => i.ImportRunID)
    

    【讨论】:

    • 还是有错误。 “无法将类型 'Dbcontext.ImportRunTable' 隐式转换为 'bool'” “无法将 lambda 表达式转换为预期的委托类型,因为块中的某些返回类型不能隐式转换为委托返回”
    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2017-11-17
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    相关资源
    最近更新 更多