c# - Best Practices: Adding properties to a LINQ-to-Entities query result? -


i'm writing asp.net web pages application , in it, have massive linq entities query. query pulls data table in database, filters it, groups data twice, , adds properties result set. loop through table, outputting rows.

the query quite big, sorry:

accountorders = db.eventorders     .where(order => order.eventid == eventid)     .orderby(order => order.productcode)     .groupby(order => new { order.accountnum, order.exhibitor, order.booth })     .select(orders =>          new {             key = orders.key,             productorders = orders                 .groupby(order => new { order.productcode, order.product, order.price })                 .select(productorders =>                      new {                         key = productorders.key,                         quantity = productorders.sum(item => item.quantity),                         htmlid = string.join(",", productorders.select(o => (o.ordernum + "-" + o.orderline))),                          assignedlines = productorders.selectmany(order => order.lineassignments)                     })         })         .select(account =>              new {                  key = account.key,                  // property see whether booth number should displayed                 hasbooth = !string.isnullorwhitespace(account.key.booth),                  hasassigneddigitallines = account.productorders.any(order => order.assignedlines.any(line => line.type == "digital")),                  // dividing orders respective product group                 phoneorders      = account.productorders.where(prod => productcodes.phone_codes.contains(prod.key.productcode)),                 internetorders   = account.productorders.where(prod => productcodes.internet_codes.contains(prod.key.productcode)),                 additionalorders = account.productorders.where(prod => productcodes.additional_codes.contains(prod.key.productcode))             })         .tolist(); 

i use added properties style output. example, use hasbooth property check whether or not should output booth location in brackets beside exhibitor name. problem have save big query ienumerable, meaning error: cannot use lambda expression argument dynamically dispatched operation without first casting delegate or expression tree type. should manipulating query way?

any advice appreciated!

at point, passing in dynamic datatype method, in turn changes return type dynamic. can either cast dynamic type type recognised @ compile time or explicitly set return type instead of using var.

you can read more issue here: http://www.mikesdotnetting.com/article/198/cannot-use-a-lambda-expression-as-an-argument-to-a-dynamically-dispatched-operation


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -