C# Joins/Where with Linq and Lambda how to return a List<T> -


the query below works fine , returns 1 list<> expected

list<purchaseorderheaderentity> details = (from p in  db.purchaseorderdetailentity join r in db.purchaseorderheaderentity on  p.purchaseorderid equals  r.purchaseorderid   p.productid == productid select r).tolist(); 

if rewrite using lambda, returns 2 lists:

list<purchaseorderheaderentity> lambda_details = db.purchaseorderdetailentity.join(db.purchaseorderheaderentity,                     p => p.purchaseorderid,                     r => r.purchaseorderid,                     (p, r) => new { detail = p, header = r }).where(detailandheader => detailandheader.detail.productid == productid).tolist(); 

if remove "detail=p" selection part, join throws error

"the type arguments method ... cannot inferred usage. try specifying type arguments explicitly."

is there way rewrite query make return 1 list header?

thanks lot in advance!

you can put condition before join, can return r.

var lambda_details = db.purchaseorderdetailentity              .where(detailandheader => detailandheader.detail.productid == productid)              .join(db.purchaseorderheaderentity,                         p => p.purchaseorderid,                         r => r.purchaseorderid,                         (p, r) => r).tolist(); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -