-
-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathProgram.cs
More file actions
84 lines (71 loc) · 3.22 KB
/
Program.cs
File metadata and controls
84 lines (71 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text.Json;
using System.Threading.Tasks;
using ConsoleAppEF2.Database;
using Microsoft.EntityFrameworkCore;
namespace ConsoleApp_net5_0_EF6_InMemory;
static class Program
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };
static async Task Main(string[] args)
{
await using (var context = new TestContextEF6())
{
context.Products.Add(new ProductDynamic { NullableInt = 1, Key = 123, Dict = new Dictionary<string, object> { { "Name", "test" } } });
context.Products.Add(new ProductDynamic { NullableInt = 2, Key = 456, Dict = new Dictionary<string, object> { { "Name1", "test1" } } });
await context.SaveChangesAsync();
}
// #784
await using (var context = new TestContextEF6())
{
var result784 = context.Products.Where("NullableInt = @0", 1).ToDynamicArray<ProductDynamic>();
Console.WriteLine("a1 {0}", string.Join(", ", result784.Select(r => r.Key)));
}
await using (var context = new TestContextEF6())
{
var intType = typeof(int).FullName;
var a1 = context.Products.Select($"\"{intType}\"(Key)").ToDynamicArray();
Console.WriteLine("a1 {0}", string.Join(",", a1));
var a2 = context.Products.Select($"\"{intType}\"?(Key)").ToDynamicArray();
Console.WriteLine("a2 {0}", string.Join(",", a2));
}
await using (var context = new TestContextEF6())
{
var resultsNormal = context.Products.Where(p => p.Dict["Name"] == "test").ToListAsync();
var results1 = await context.Products.Where("Dict.Name == @0", "test").ToListAsync();
Console.WriteLine("results1:");
foreach (var result in results1)
{
Console.WriteLine(result.Key + ":" + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
var results2 = await context.Products.Where("Dict.Name == @0", "test").ToDynamicListAsync();
Console.WriteLine("results2:");
foreach (var result in results2)
{
Console.WriteLine(result.Key + ":" + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
var results3 = await context.Products.Where("NullableInt == 1").ToDynamicListAsync(typeof(ProductDynamic));
Console.WriteLine("results3:");
foreach (var result in results3)
{
Console.WriteLine(result.Key + ":" + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
}
// #907 and #912
await using (var context = new TestContextEF6())
{
var dynamicData = context.Products
.AsQueryable()
.Select("new { NullableInt as Value }")
.ToDynamicArray();
var dynamicResult = dynamicData
.AsQueryable()
.Select("Value")
.ToDynamicArray();
Console.WriteLine("#907 and #912 = {0}", string.Join(", ", dynamicResult));
}
}
}