Link to home
Start Free TrialLog in
Avatar of countrymeister
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(dataRows2["StartPrice"]),
                                EndPrice = Convert.ToDecimal(dataRows2["EndPrice"])

                            }).Distinct().ToList();
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of countrymeister
countrymeister

ASKER

I removed the distinct that did not help
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
How many rows are you getting back?
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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial