Home > Net >  Lambda how to write a groupby
Lambda how to write a groupby

Time:09-26

TSalesr table has the date and amount field, including the date when the field is (date) (month) (year), I want to grouping by date total amount, total a value on the same day

Var sum=_dbContext. TSales. Where (a=& gt; A. d. ate. The Value & gt;=dt1 & amp; & A. d. ate. The Value & lt;=dt2)
GroupBy (a=& gt; A. d. ate. Value)
. Select (a=& gt; New {
Sum_amount=a.S um (b=& gt; B.a mount)}). ToList ()

But such code is grouped by minutes when (date) (month) (year), how can be grouped by day?

CodePudding user response:

GroupBy (a=& gt; A. d. ate. Day)

CodePudding user response:

That is probably what you mean,

CodePudding user response:

reference 1st floor is nu month god reply:
GroupBy (a=& gt; A. d. ate. Day



I changed to
GroupBy (a=& gt; A. d. ate. Value. The Date)
Error is as follows:
LINQ to Entities do not support the specified type members "Date", only supports the initializers, members of the entity and entity navigation attribute

Later changed to
GroupBy (a=& gt; DbFunctions. TruncateTime (a. d. ate. Value))
It is ok to!!!!!

CodePudding user response:

reference set home early reply: 3/f
Quote: refer to 1st floor is nu month god reply:

GroupBy (a=& gt; A. d. ate. Day



I changed to
GroupBy (a=& gt; A. d. ate. Value. The Date)
Error is as follows:
LINQ to Entities do not support the specified type members "Date", only supports the initializers, members of the entity and entity navigation attribute

Later changed to
GroupBy (a=& gt; DbFunctions. TruncateTime (a. d. ate. Value))
It is ok to!!!!!

Oh, this is because don't know your method when SQL linq conversion,
Need DbFunctions. TruncateTime to help convert your SQL
  •  Tags:  
  • LINQ
  • Related