I want to get 2 values returned by my query. How to do, using linq-to-entity

Posted by Shantanu Gupta on Stack Overflow See other posts from Stack Overflow or by Shantanu Gupta
Published on 2010-05-26T09:43:36Z Indexed on 2010/05/26 11:01 UTC
Read the original article Hit count: 262

Filed under:
|
|
|
            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 new 
                                {
                                    dept_id=dept.Field<long>("DEPARTMENT_ID")
                                    ,dept_name=dept.Field<long>("DEPARTMENT_NAME")
                                }).Distinct();


            DataTable dt = new DataTable();
            dt.Columns.Add("DEPARTMENT_ID");
            dt.Columns.Add("DEPARTMENT_NAME");
            foreach (long? dept_ in dept_list)
            {
                dt.Rows.Add(dept_[0], dept_[1]);
            }

EDIT

In the previous question asked by me.

I got an answer like this for single value. What is the difference between the two ?

foreach (long? dept in dept_list) {
    dt.Rows.Add(dept);
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ