Saturday, 15 August 2015

.net - Why is GroupBy multiple fields not grouping correctly> -


I have found a model object with a timestamp asset, and I want to group in this year and month, so I did this:

Months of events up to months dull month = model Aventus New {x.Timestamp.Year, x.Timestamp.Month}} with group (function (x)

but this is actually returning a group for every event, even so With that same year and month: wrong grouping

what's going on here is? Instead of a group based on year and month, why is GroupBy creating a separate group for each event, and how can I fix it?

only the fixed key property equality determines if no major properties , You get the reference equality.

  with new {key x.Timestamp.Year, Key x.Timestamp.Month}  

Key Properties

Key properties are different from non-core properties in many basic ways:

  • To define properties It is done whether two examples are the same.

  • The values ​​of the key properties are read-only and can not be changed.

  • Only the key property value is included in the compiler-generated hash code algorithm for an anonymous type.

Parallels

Anonymized type of examples can be the same if they are the same anonymous type examples. Examples consider the same type of example as if they meet the following conditions:

  • They are declared in the same assembly.

  • The names are the same as their properties, they are the approximate types, and they are declared in the same order.

  • In each, the same properties are marked as the key properties.

  • At least one asset is an important asset in each manifestation.

There is no instance of an anonymous type in which there is no major quality, it is similar to that only.

to


No comments:

Post a Comment