c# - LINQ query works in LINQPad, but not in VS -


i'm using entity framework, getting when hits last line :

the methods 'single' , 'singleordefault' can used final query operation. consider using method 'firstordefault' in instance instead.

my query is:

 var orderitems =    orderitem in db.order_productitem    join style in db.products_styles on orderitem.style equals style.index    orderitem.salesorderid == salesorderid &&          (orderitem.isdeleted==null || orderitem.isdeleted.value == false)    group new { orderitem, style } orderitem.frameno grp    select new orderitemmodel    {        frameno = grp.key,        //count = grp.select(x => x.orderitem.frameno).count(),        totalcost = grp.sum(x => x.orderitem.costprice),        overallwidth = grp.single(x => x.orderitem.hardwaretype == 3).orderitem.overallwidth,        overallheight = grp.single(x => x.orderitem.hardwaretype == 3).orderitem.overallheight,        name = grp.select(x => x.style.name).first(),        imagepath = grp.select(x => x.style.external_image_path).first()    };  var orders =  orderitems.tolist(); 

seems work okay in linqpad/linq sql....

any ideas what's wrong?

there difference between single() , first().

overallwidth = grp.single(x => x.orderitem.hardwaretype == 3).orderitem.overallwidth 

this throw exception, if query return more 1 result, totally possible, because there more 1 item returned of hadwaretype 3. single() expects excactly 1 return value

use first or firstordefault instead. if more 1 resultset returned take first one.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -