简体   繁体   中英

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

            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);
}
foreach (var dept_ in dept_list)
{
   dt.Rows.Add(dept_.dept_id, dept_dept_name);
}

answer for EDIT

I guess that in your previous question dept_list was of type IEnumerable but in this question it is of type IEnumerable where T is an anonymous type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM