Lambda expression query experience: Use of IN and groupby, lambdagroupby
Lambda In usage:
Lambda expression query does not use the IN method. You can modify whether the in query array is included IN the set of the ing object:
The following code:
Var initialize mentids = input. specified mentids. split (','). select (s => int. parse (s )). toList (); // This Is A String Array passed in from the front end and needs to be converted to intdb. whereLambda. add (d => extends mentids. contains (d. extends mentid); // wherelamdba is the lambda expression in the where condition, and db is the context data. This statement indicates whether the object set contains javasmentids.
SQL: select * from db where partition mentid in (partition mentids)
Lambda groupby usage
Calculate various statistics in the database using group
The group by statement is used in combination with the aggregate function to GROUP result sets based on one or more columns.
Then, the computation involves a lot of computing statistics in the database.
We useLambdaExpression queries can also be implemented.
// GROUP BYvar rels = rel. GroupBy (a => a. PlatformName). Select (s => new MarketInfoInvalidRatioExtend
{BusinessName = s. key, AssignNum = s. sum (c => c. assignNum), InvalidNum = s. sum (I => I. invalidNum )}). toList (); // multiple groups BYvar rel = db. findList (10000, db. whereLambda, B => B. MKBTID, true ). groupBy (g => new
{G. PlatformName, g. BusinessName, g. DepartmentName, g. ResourceName}). Select (s => new MarketInfoInvalidRatioExtend
{PlatformName = s. Key. PlatformName, BusinessName = s. Key. BusinessName, DepartmentName = s. Key. DepartmentName, ResourceName = s. Key. ResourceName,
AssignNum = s. sum (w => w. assignNum), EmptyNum = s. sum (w => w. emptyNum), BlacklistNum = s. sum (w => w. blacklistNum), ErrorNum = s. sum (w => w. errorNum ),
InvalidNum = s. Sum (w => w. InvalidNum )});
Note that the Select NEW object itself cannot be the same as the queried set object. Otherwise, the error "unable to construct entity or complex type" "will be reported in the LINQ to Entities query """.