c# - unable to create a constant value of type anonymous type only primitive types -
using entity framework version=6.0.0.0 get common id , orderid shown below.
var dt1 = p in dt.asenumerable() select new { id = p.field<int>("id"), orderid = p.field<int>("orderid") }; var dt2 = (from order in db.orders select new { order.id, order.orderid }).tolist(); var intersect = dt1.intersect(dt2); based on list of values in intersect. need select values orders table.
trying used code getting error "unable create constant value of type anonymous type primitive types"
var result= (from in sync.orders intersect.any(b => a.id == b.id && a.orderid == b.orderid) select a).tolist();
you trying "join" ef query in-memory data set, not work because there's not way embed list , lookup in sql. 1 option pull entire table memory asenumerable:
var result= (from in sync.orders.asenumberable intersect.any(b => a.id == b.id && a.orderid == b.orderid) select a).tolist(); another option concatenate id , orderid 1 value , use contains since can translated in clause in sql:
var lookup = intersect.select(i => i.id + "-" + i.orderid).tolist(); var result= (from in sync.orders lookup.contains(a.id + "-" + a.orderid) select a).tolist();
Comments
Post a Comment