views:

290

answers:

1

I have created this query to fetch some result from database. Here is my table structure.

What exaclty is happening.

DtMapGuestDepartment as Table 1

DtDepartment as Table 2

Are being used

    var dept_list=  from map in DtMapGuestDepartment.AsEnumerable()
                    where map.Field<Nullable<long>>("GUEST_ID") == DRowGuestPI.Field<Nullable<long>>("PK_GUEST_ID")
                    join 
                    dept in DtDepartment.AsEnumerable()
                    on map.Field<Nullable<long>>("DEPARTMENT_ID") equals dept.Field<Nullable<long>>("DEPARTMENT_ID")
                    select dept.Field<string>("DEPARTMENT_ID");

I am performing this query on DataTables and expect it to return me a datatable.

Here I want to select distinct department from Table 1 as well which will be my next quest. Please answer to that also if possible.

+1  A: 

break your query into parts and see which collection has no elements.

var mapList = DtMapGuestDepartment.AsEnumerable().ToList();
var deptList = DtDepartment.AsEnumerable().ToList();

var queryResult1 = (
  from map in mapList
  where map.Field<Nullable<long>>("GUEST_ID") ==
    DRowGuestPI.Field<Nullable<long>>("PK_GUEST_ID") 
  select map
).ToList();

var queryResult2 = (
  from map in queryResult1
  join dept in deptList
    on map.Field<Nullable<long>>("DEPARTMENT_ID")
    equals dept.Field<Nullable<long>>("DEPARTMENT_ID") 
  select dept.Field<string>("DEPARTMENT_ID")
).ToList();
David B
@David: Thx for support, although I resolved the problem in the same way u told, but an hour or two before your answer.
Shantanu Gupta