Skip to content

Commit

Permalink
group by should work, just ToList is not supported by ef core.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lebee committed Nov 27, 2019
1 parent fc0510f commit 7d9755e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions PoweredSoft.DynamicLinq.Test/EntityFrameworkCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using PoweredSoft.DynamicLinq;
using Microsoft.EntityFrameworkCore;
using PoweredSoft.DynamicLinq.EntityFrameworkCore;
using PoweredSoft.DynamicLinq.Test.Helpers;

namespace PoweredSoft.DynamicLinq.Test
{
Expand Down Expand Up @@ -114,6 +115,38 @@ public void TestWhereAnd()
Assert.IsNotNull(author);
}

[TestMethod]
public void GroupBy()
{
var context = GetCoreContext(nameof(TestWhereOr));
SeedForTests(context);

var authorsWithFamilyNameCount = context.Authors
.GroupBy(t => new
{
t.LastName,
t.FirstName
}).Select(t => new
{
t.Key,
Count = t.Count()
}).ToList();

var authorsWithFamilyNameCountDynamic = context.Authors
.GroupBy(t => t.Path("FirstName").Path("LastName"))
.Select(t => t.Key("FirstName", "FirstName").Key("LastName", "LastName").Count("Count"))
.ToDynamicClassList();

Assert.AreEqual(authorsWithFamilyNameCount.Count, authorsWithFamilyNameCountDynamic.Count);
for(var i = 0; i < authorsWithFamilyNameCount.Count; i++)
{
Assert.AreEqual(authorsWithFamilyNameCount[i].Key.FirstName, authorsWithFamilyNameCountDynamic[i].GetDynamicPropertyValue("FirstName"));
Assert.AreEqual(authorsWithFamilyNameCount[i].Key.LastName, authorsWithFamilyNameCountDynamic[i].GetDynamicPropertyValue("LastName"));
Assert.AreEqual(authorsWithFamilyNameCount[i].Count, authorsWithFamilyNameCountDynamic[i].GetDynamicPropertyValue("Count"));
}
}


[TestMethod]
public void TestWhereOr()
{
Expand Down

0 comments on commit 7d9755e

Please sign in to comment.