forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (52 loc) · 2.42 KB
/
Program.cs
File metadata and controls
62 lines (52 loc) · 2.42 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
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, Dict = new Dictionary<string, object> { { "Name", "test" } } });
context.Products.Add(new ProductDynamic { NullableInt = 2, Dict = new Dictionary<string, object> { { "Name1", "test1" } } });
await context.SaveChangesAsync();
}
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));
}
}
}
}