c# - LINQ JOIN Straight to Object -
c# - LINQ JOIN Straight to Object -
i rather new linq , have implemented linq statement bring together , results of query, iterate through results , assign each result new object , add together object list of objects. there more elegant way next such selecting right object list?
thanks , much appreciated
var clubattendeeeducationlist = new list<clubattendeeeducation>(); var r = (from oer in db.onlineeducationregistrations bring together oec in db.onlineeducationcourses on oer.onlineeducationcourseid equals oec.onlineeducationcourseid (oer.mastercustomerid.equals(userid) && oer.datecompleted >= start.date && oer.datecompleted <= upuntil.date && oer.datecompleted != null) select new {onlineeducationregistration = oer, oec.coursetitle}).tolist(); foreach (var item in r) { var educationitem = new clubattendeeeducation { session = item.coursetitle, date = item.onlineeducationregistration.datecompleted.value }; clubattendeeeducationlist.add(educationitem); } homecoming clubattendeeeducationlist;
just creating new anonymous object in query can create object of type want, , turn result list.
var clubattendeeeducationlist = (from oer in db.onlineeducationregistrations /* rest of query */ select new clubattendeeeducation { session = item.coursetitle, date = item.onlineeducationregistration.datecompleted.value }).tolist();
c# linq
Comments
Post a Comment