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
51 lines (43 loc) · 1.96 KB
/
Program.cs
File metadata and controls
51 lines (43 loc) · 1.96 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
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_EF5_InMemory;
static class Program
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { WriteIndented = true };
static async Task Main(string[] args)
{
await using (var context = new TestContextEF5())
{
context.Products.Add(new ProductDynamic { NullableInt = 1, Dict = new Dictionary<string, object> { { "Name", "test" } } });
context.Products.Add(new ProductDynamic { NullableInt = null, Dict = new Dictionary<string, object> { { "Name2", "test2" } } });
await context.SaveChangesAsync();
}
await using (var context = new TestContextEF5())
{
var results = context.Products.Where("Dict.Name == @0", "test");
Console.WriteLine("results = ?");
foreach (var result in results)
{
Console.WriteLine(result.Key + ": " + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
var orderedResults = context.Products.OrderBy("np(NullableInt)");
foreach (var result in orderedResults)
{
Console.WriteLine(result.Key + ": " + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
// This fails: https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/541
var query = EF.CompileQuery<TestContextEF5, string, ProductDynamic>((ctx, ordering) => ctx.Products.OrderBy(ordering));
var enumerable = query.Invoke(context, "Name ASC");
foreach (var result in enumerable)
{
Console.WriteLine(result.Key + ": " + JsonSerializer.Serialize(result.Dict, JsonSerializerOptions));
}
}
}
}