Skip to content

Commit 43506d8

Browse files
committed
tests
1 parent c4be241 commit 43506d8

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src-console/ConsoleAppEF6_InMemory/Program.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static async Task Main(string[] args)
2626
await using (var context = new TestContextEF6())
2727
{
2828
var result784 = context.Products.Where("NullableInt = @0", 1).ToDynamicArray<ProductDynamic>();
29-
Console.WriteLine("a1 {0}", string.Join(",", result784.Select(r => r.Key)));
29+
Console.WriteLine("a1 {0}", string.Join(", ", result784.Select(r => r.Key)));
3030
}
3131

3232
await using (var context = new TestContextEF6())
@@ -65,5 +65,20 @@ static async Task Main(string[] args)
6565
Console.WriteLine(result.Key + ":" + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
6666
}
6767
}
68+
69+
// #907 and #912
70+
await using (var context = new TestContextEF6())
71+
{
72+
var dynamicData = context.Products
73+
.AsQueryable()
74+
.Select("new { NullableInt as Value }")
75+
.ToDynamicArray();
76+
var dynamicResult = dynamicData
77+
.AsQueryable()
78+
.Select("Value")
79+
.ToDynamicArray();
80+
81+
Console.WriteLine("#907 and #912 = {0}", string.Join(", ", dynamicResult));
82+
}
6883
}
6984
}

src-console/ConsoleApp_net6.0/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class GroupedSalesData
3333
public string Region { get; set; }
3434
public string? Product { get; set; }
3535
public int TotalSales { get; set; }
36-
3736
public int GroupLevel { get; set; }
3837
}
3938

@@ -83,14 +82,14 @@ private static void Q912()
8382
// GROUPING SET 1: (Region, Product)
8483
var detailed = rows
8584
.GroupBy("new (Region, Product)")
86-
.Select("new (Key.Region as Region, Key.Product as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 0 as GroupLevel)");
85+
.Select<GroupedSalesData>("new (Key.Region as Region, Key.Product as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 0 as GroupLevel)");
8786

8887
// GROUPING SET 2: (Region)
8988
var regionSubtotal = rows
9089
.GroupBy("Region")
91-
.Select("new (Key as Region, null as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 1 as GroupLevel)");
90+
.Select<GroupedSalesData>("new (Key as Region, null as Product, Sum(Convert.ToInt32(Sales)) as TotalSales, 1 as GroupLevel)");
9291

93-
var combined = detailed.ToDynamicArray().Concat(regionSubtotal.ToDynamicArray()).AsQueryable();
92+
var combined = detailed.Concat(regionSubtotal).AsQueryable();
9493
var ordered = combined.OrderBy("Product").ToDynamicList();
9594

9695
int x = 9;

test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections;
22
using System.Linq.Dynamic.Core.Exceptions;
3+
using FluentAssertions;
34
using Newtonsoft.Json;
45
#if EFCORE
56
using Microsoft.EntityFrameworkCore;
@@ -142,4 +143,25 @@ public void Entities_Select_DynamicClass_And_Call_Any()
142143
// Assert
143144
Assert.True(result);
144145
}
146+
147+
/// <summary>
148+
/// #907
149+
/// </summary>
150+
[Fact]
151+
public void Entities_Select_DynamicClass_And_Select_DynamicClass()
152+
{
153+
// Act
154+
var dynamicData = _context.Blogs
155+
.Take(2)
156+
.Select("new (BlogId as I, Name as N)")
157+
.ToDynamicArray();
158+
159+
// Assert
160+
var dynamicResult = dynamicData
161+
.AsQueryable()
162+
.Select("I")
163+
.ToDynamicArray();
164+
165+
dynamicResult.Should().BeEquivalentTo([1000, 1001]);
166+
}
145167
}

0 commit comments

Comments
 (0)