Lambda expression query experience: Use of IN and groupby, lambdagroupby

Source: Internet
Author: User

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 """.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.