Why I am getting Null from this statement. Query Syntax in C#

Posted by Shantanu Gupta on Stack Overflow See other posts from Stack Overflow or by Shantanu Gupta
Published on 2010-05-26T08:13:52Z Indexed on 2010/05/26 8:21 UTC
Read the original article Hit count: 702

This is not working. Returns Null to dept_list.

        var dept_list = ((from map in DtMapGuestDepartment.AsEnumerable()
                         where map.Field<Nullable<long>>("Guest_Id") == 174
                         select map.Field<Nullable<long>>("Department_id")).Distinct())as IEnumerable<DataRow>;
       DataTable dt = dept_list.CopyToDataTable(); //dept_list comes null here

This works as desired.

        var dept_list = from map in DtMapGuestDepartment.AsEnumerable()
                         where map.Field<Nullable<long>>("Guest_Id") == 174
                         select map;
       DataTable dt = dept_list.CopyToDataTable(); //when used like this runs correct.

What mistake is being done by me here. ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ