I’m writing a query that returns a list of models that needs data from two tables and I’m hoping the let keyword can help me. I’m starting like this:
var TheListOfModels =
let Data1 = (from a in MyDC.Table1
where ....
select new ObjectThatContainsData1()
{
}).ToList()
let Data2 = (from b in MyDC.Table2
where ....
select new ObjectThatContainsData2()
{
}).Tolist()
select new ObjectThatContainsBothData()
{
SomeProp1 = from p in Data1
select everything
SomeProp2 = from a in Data2
select everything
}).ToList()
I’m not too sure on how to proceed and write the final select statement that selects from the result of the 2 let clauses rather than directly from tables. Is the structure of the query I’m writing a good starting point or should I write it another way?
Thanks.
Edit per comment: table definitions
Table1 looks somewhat like this:
PeachID | UserID | HarvestDateTime | SomeOtherColumn
Table2 looks like that:
AppleID | UserID | HarvestDateTime | SomeOtherColumn
I’m looking to extract all the peaches and apples into a list of the ObjectThatContainsBothData and the where clause is basically there to filter the HarvestDateTime and the UserID
Looks like you are trying to apply Linq query syntax to ordinal C# code. Just create your object and execute two queries to get data fro both properties: