views:

32

answers:

1

Hi, i want to use linq to fetch data from datatable.I have 2 tables in Cache and i want to join these tables then get value from resultset.I pasted Original Sql query and my linq query here.My linq query returns nothing.Where do i miss?My original sql query returns 1 row ,but q1 is nothing

'Original Sql query

select b.FL_DSD from LU_CUSTOMER a, LU_TYPE b where a.ID_TYPE=b.ID_TYPE and a.ID_NO=355

My Linq Query

Dim q1 = From c In cls_StaticData.Get_Data(cls_StaticData.Tables.LU_CUSTOMER) Where c.Item("ID_NO") = 355 Join _
 o In cls_StaticData.Get_Data(cls_StaticData.Tables.LU_TYPE) On c.Item("ID_TYPE") Equals o.Item("ID_TYPE")
A: 

Are you sure that your second table has an ID_TYPE record that matches the value from your first table? You may be inner joining your data away. Turn the Linq query into a LEFT OUTER JOIN like this and see if you get data back. If so, you're either missing the lookup from your right-hand datatable, or your Equals comparison is having trouble somewhere.

Dim q1 = From c In cls_StaticData.Get_Data(cls_StaticData.Tables.LU_CUSTOMER) _
Where c.Item("ID_NO") = 355 _
Group Join o In cls_StaticData.Get_Data(cls_StaticData.Tables.LU_TYPE) _
On c.Item("ID_TYPE") Equals o.Item("ID_TYPE") _
Into joinedMatches = Group _
From matchedRight In joinedMatches.DefaultIfEmpty() _
Select New With {.Left = c, .Right = matchedRight}
mattmc3