语句如下:
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.