Problem handling for LINQ Mysql groupby statements

Source: Internet
Author: User

语句如下:
                varResumelist =db.                Channelresume.where (model); varGroupvalues = resumelist.groupby (t =New{t.agentid, t.agentname}); varStatistics = groupvalues.select (c =NewResumestatisticsviewmodel () {Date=Datespan, Agentid=C.key.agentid, AgentName=C.key.agentname, TotalCount=C.count (), Validcount= C.count (k = K.status = = (int) (Resumestatus.valid)}); Try                {                    //statistics = statistics. (c = c.agentname);                    varTMP =statistics.                                    ToList (); }                Catch(Exception ex) {Console.WriteLine (ex).                    Message); Throw; }

As shown above, directly using the Select final data for GroupBy objects will return an error, and LINQ resolves the SQL statement to Agentid, agentname the two grouping conditions are not used as fields in the staging table. Results in the last complete SQL statement execution error: "Unknown column ' Groupby1.k1 ' in ' Field List '"

Two addresses were found on the Internet:

http://bugs.mysql.com/bug.php?id=46742

Http://stackoverflow.com/questions/15083627/linq-mysql-group-by-year-month-day-select-year-month-day-count

But no solution was seen.

Then try to do a foreach loop directly on the groupvalues variable.

                varResumelist =db.                Channelresume.where (model); varGroupvalues = resumelist.groupby (t =New{t.agentid, t.agentname}); foreach(varIteminchgroupvalues) {                    varViewModel =NewResumestatisticsviewmodel () {Date=Datespan, Agentid=item. Key.agentid, AgentName=item. Key.agentname, TotalCount=item. Count (), Validcount= Item. Count (t = = T.status = = (int) resumestatus.valid)}; Result.                ADD (ViewModel); }                return NewPagedlist<resumestatisticsviewmodel> (result, m.page, m.pagesize);

This normal execution, no error.

The feeling is that a LINQ Mysql GROUPBY statement is used in conjunction with a select bug.

Something, LINQ statements do have performance problems, and if not split write code too verbose, really should be split, keep the code in the operation of the database as far as possible fast track approach.

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.