1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Linq . Dynamic . Core ;
5+ using System . Text . Json ;
6+ using System . Threading . Tasks ;
7+ using ConsoleAppEF2 . Database ;
8+ using Microsoft . EntityFrameworkCore ;
9+
10+ namespace ConsoleApp_net6_0_EF6_Sqlite ;
11+
12+ static class Program
13+ {
14+ private static readonly JsonSerializerOptions JsonSerializerOptions = new ( ) { WriteIndented = true } ;
15+
16+ static async Task Main ( string [ ] args )
17+ {
18+ await using ( var context = new TestContextEF6 ( ) )
19+ {
20+ await context . Database . EnsureDeletedAsync ( ) ;
21+ await context . Database . EnsureCreatedAsync ( ) ;
22+
23+ context . Products . Add ( new ProductDynamic { NullableInt = 1 , Key = 123 , Dict = new Dictionary < string , object > { { "Name" , "test" } } } ) ;
24+ context . Products . Add ( new ProductDynamic { NullableInt = 2 , Key = 456 , Dict = new Dictionary < string , object > { { "Name1" , "test1" } } } ) ;
25+ await context . SaveChangesAsync ( ) ;
26+ }
27+
28+ // #784
29+ await using ( var context = new TestContextEF6 ( ) )
30+ {
31+ var config = new ParsingConfig
32+ {
33+ UseParameterizedNamesInDynamicQuery = true
34+ } ;
35+
36+ var result784 = context . Products . Where ( config , "NullableInt = @0" , 1 ) . ToDynamicArray < ProductDynamic > ( ) ;
37+ Console . WriteLine ( "a1 {0}" , string . Join ( "," , result784 . Select ( r => r . Key ) ) ) ;
38+ }
39+
40+ return ;
41+
42+ await using ( var context = new TestContextEF6 ( ) )
43+ {
44+ var intType = typeof ( int ) . FullName ;
45+
46+ var a1 = context . Products . Select ( $ "\" { intType } \" (Key)") . ToDynamicArray ( ) ;
47+ Console . WriteLine ( "a1 {0}" , string . Join ( "," , a1 ) ) ;
48+
49+ var a2 = context . Products . Select ( $ "\" { intType } \" ?(Key)") . ToDynamicArray ( ) ;
50+ Console . WriteLine ( "a2 {0}" , string . Join ( "," , a2 ) ) ;
51+ }
52+
53+ await using ( var context = new TestContextEF6 ( ) )
54+ {
55+ var resultsNormal = context . Products . Where ( p => p . Dict [ "Name" ] == "test" ) . ToListAsync ( ) ;
56+
57+ var results1 = await context . Products . Where ( "Dict.Name == @0" , "test" ) . ToListAsync ( ) ;
58+ Console . WriteLine ( "results1:" ) ;
59+ foreach ( var result in results1 )
60+ {
61+ Console . WriteLine ( result . Key + ":" + JsonSerializer . Serialize ( result . Dict , JsonSerializerOptions ) ) ;
62+ }
63+
64+ var results2 = await context . Products . Where ( "Dict.Name == @0" , "test" ) . ToDynamicListAsync ( ) ;
65+ Console . WriteLine ( "results2:" ) ;
66+ foreach ( var result in results2 )
67+ {
68+ Console . WriteLine ( result . Key + ":" + JsonSerializer . Serialize ( result . Dict , JsonSerializerOptions ) ) ;
69+ }
70+
71+ var results3 = await context . Products . Where ( "NullableInt == 1" ) . ToDynamicListAsync ( typeof ( ProductDynamic ) ) ;
72+ Console . WriteLine ( "results3:" ) ;
73+ foreach ( var result in results3 )
74+ {
75+ Console . WriteLine ( result . Key + ":" + JsonSerializer . Serialize ( result . Dict , JsonSerializerOptions ) ) ;
76+ }
77+ }
78+ }
79+ }
0 commit comments