countrymeister
asked on
LINQ to SQL
I have two datatables T1 and T2
I neeed to do a join but only get the first or default from T2
Because T2 could have multiple rows that match the join condition
I tried this
var result = (from dataRows1 in T1.AsEnumerable()
join dataRows2 in T2.AsEnumerable()
on dataRows1["ID"] equals dataRows2["ID"]
select new Returns
{
ID = dataRows1["ID"],
Date = dataRows1["Date"],
StartPrice = Convert.ToDecimal(dataRows 2["StartPr ice"]),
EndPrice = Convert.ToDecimal(dataRows 2["EndPric e"])
}).Distinct().ToList();
I neeed to do a join but only get the first or default from T2
Because T2 could have multiple rows that match the join condition
I tried this
var result = (from dataRows1 in T1.AsEnumerable()
join dataRows2 in T2.AsEnumerable()
on dataRows1["ID"] equals dataRows2["ID"]
select new Returns
{
ID = dataRows1["ID"],
Date = dataRows1["Date"],
StartPrice = Convert.ToDecimal(dataRows
EndPrice = Convert.ToDecimal(dataRows
}).Distinct().ToList();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
How many rows are you getting back?
ASKER
I am getting 4890 rows back
I have tried similar Linq query and it seems to work on my systems as expected.
Running the query using the Distinct() method and you tell me the number of records returned?
Also can you post a screen shot of the results where data is missing?
Running the query using the Distinct() method and you tell me the number of records returned?
Also can you post a screen shot of the results where data is missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
t1 has 2550 rows, and T2 has 4890 rows, I just want the 2550 rows back in my join
Example t2 could have multiple rows with ID matching the ID in T1