c# - validate search result using Linq -
i have search result database,
int searchterm = "xx" var result = orderlines in context.orderlinesearch(searchterm) select new { ordernumber = orders.ordernumber, orderlineid = orders.orderlineid };
i need validate whether result contains many orders. need check whether multiple orders returned or not.
i did validation storing first order number in variable , compared whether other rows contains order number. see below
string ordernumber = result.first().ordernumber; bool isvalid = result.where(x => x.ordernumber != ordernumber).count() == 0;
i want know best way validate using linq? can 1 me?
thanks in advance.
may should try group results ordernumber , calculate count?
var result = orderlines in context.orderlinesearch(searchterm) group orderlines orderlines.ordernumber g select g.key bool haselements = result.any();
Comments
Post a Comment