Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
2.11.2
-
None
-
C# .Net
Description
Im writing some service in C# and I have to use MongoDB.Driver 2.11.2. I have some issue when grouping my list of items. It looks like a bug. This is my code:
var totals = Collection.AsQueryable().GroupBy(s => s.StoreId, (key, group) => new Test |
{
|
Key = key,
|
|
|
LabOnHandTestCount =
|
group.Count(groupItem => groupItem.IsLab.HasValue && groupItem.IsLab.Value),
|
|
|
LabOnHandPrice =
|
group.Where(groupItem => groupItem.IsLab.HasValue && groupItem.IsLabd.Value)
|
.Sum(z => z.TotalCost),
|
|
|
|
|
LabOnHandPrice2 =
|
group.Sum(g=> g.IsLa.HasValue && g.IsLab.Value ? g.TotalCost:0), |
|
|
LabOnHandPrice3 =
|
group.Where(gg => gg.IsLab.Value == true).Sum(s=>s.TotalCost), |
|
|
}).ToList();
|
I got different results from next lines.
- first line:
LabOnHandPrice = group.Where(groupItem => groupItem.IsLab.HasValue && groupItem.IsLabd.Value)
|
.Sum(z => z.TotalCost)
|
- second line(the right result):
LabOnHandPrice2 = group.Sum(g=> g.IsLa.HasValue && g.IsLab.Value ? g.TotalCost:0), |
It looks like "Where" method of "first line" got ignored and calculation performed on wrong values. And also the result of the "first line" does not changes if i change a condition. I did not find any information on MongoDB official site.
Why "Where" method got ignored and i have different results? Is there any solution?
Tnx in advance.
Attachments
Issue Links
- is related to
-
CSHARP-4063 Support Nullable HasValue and Value properties in LINQ3
-
- Closed
-