linq - Assign two tables join result to List in c# -
i'd return 2 tables result list .
public list<dynamic> getstatistics(datetime startdate , datetime enddate) { try { list<dynamic> result = new list<dynamic>(); using (xactetlentities xactctxt = new xactetlentities()) { var query = (from in xactctxt.xactetl_activity_log join b in xactctxt.xactetl_shred_mode on a.shredmodeid equals b.shredmodeid a.createddate >= startdate && a.createddate <= enddate select new { a, b }); result = query.tolist(); } }
i not able assign result query.tolist()
the problem query not ienumerable tolist() function not returning correct list type. also, anonymous types can not cast object, , internal. best bet trying make select more explicit.
instead of:
select new { a, b });
you use:
select (dynamic)new tuple<datetime, datetime>(a, b)
this result in query returning ienumerable of dynamic, each item tuple underneath.
edit: solution have query cast items objects, before converting list.
query.select(o => (object)o).tolist();
Comments
Post a Comment