Linq with EF core 2.2 Condition with where Clause FK and PK

c# entity-framework-core linq

Question

Hi im having the problem in using the where clauses with a FK and PK bacuse the FK from InstalltionÍnformation is a Object. And i cant understand it. The i => i.ImportRunID is a iqueryable and cant convert to 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);

The equivalent in MSSQL(What should be)

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

Is there a way to solve this?

1
0
4/6/2020 7:49:09 AM

Popular Answer

try use

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

instead of

context.InstallationInformation.Select(i => i.ImportRunID)
0
4/6/2020 8:17:24 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow