Skip to content

Commit 1a345d8

Browse files
committed
Add ConsoleApp_net6.0_EF6_Sqlite
1 parent 29bc5e5 commit 1a345d8

File tree

7 files changed

+176
-5
lines changed

7 files changed

+176
-5
lines changed

System.Linq.Dynamic.Core.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Te
138138
EndProject
139139
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RadzenDataGrid.BlazorApp", "src-blazor\RadzenDataGrid.BlazorApp\RadzenDataGrid.BlazorApp.csproj", "{51074A4C-15C2-4E72-81F2-2FC53903553B}"
140140
EndProject
141+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_net6.0_EF6_Sqlite", "src-console\ConsoleAppEF6_Sqlite\ConsoleApp_net6.0_EF6_Sqlite.csproj", "{CA03FD55-9DAB-4827-9A35-A96D3804B311}"
142+
EndProject
141143
Global
142144
GlobalSection(SolutionConfigurationPlatforms) = preSolution
143145
Debug|Any CPU = Debug|Any CPU
@@ -856,6 +858,22 @@ Global
856858
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x64.Build.0 = Release|Any CPU
857859
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.ActiveCfg = Release|Any CPU
858860
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.Build.0 = Release|Any CPU
861+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
862+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.Build.0 = Debug|Any CPU
863+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.ActiveCfg = Debug|Any CPU
864+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.Build.0 = Debug|Any CPU
865+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.ActiveCfg = Debug|Any CPU
866+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.Build.0 = Debug|Any CPU
867+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.ActiveCfg = Debug|Any CPU
868+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.Build.0 = Debug|Any CPU
869+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.ActiveCfg = Release|Any CPU
870+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.Build.0 = Release|Any CPU
871+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.ActiveCfg = Release|Any CPU
872+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.Build.0 = Release|Any CPU
873+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.ActiveCfg = Release|Any CPU
874+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.Build.0 = Release|Any CPU
875+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.ActiveCfg = Release|Any CPU
876+
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.Build.0 = Release|Any CPU
859877
EndGlobalSection
860878
GlobalSection(SolutionProperties) = preSolution
861879
HideSolutionNode = FALSE
@@ -905,6 +923,7 @@ Global
905923
{9000129D-322D-4FE6-9C47-75464577C374} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
906924
{ABB1BF71-8927-49BB-99F3-70BCB2CD161E} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
907925
{51074A4C-15C2-4E72-81F2-2FC53903553B} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
926+
{CA03FD55-9DAB-4827-9A35-A96D3804B311} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
908927
EndGlobalSection
909928
GlobalSection(ExtensibilityGlobals) = postSolution
910929
SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20}

System.Linq.Dynamic.Core.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<s:Boolean x:Key="/Default/UserDictionary/Words/=DLL_0027s/@EntryIndexedValue">True</s:Boolean>
77
<s:Boolean x:Key="/Default/UserDictionary/Words/=Formattable/@EntryIndexedValue">True</s:Boolean>
88
<s:Boolean x:Key="/Default/UserDictionary/Words/=renamer/@EntryIndexedValue">True</s:Boolean>
9+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sqlite/@EntryIndexedValue">True</s:Boolean>
910
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unescape/@EntryIndexedValue">True</s:Boolean>
1011
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src-console/ConsoleAppEF6_InMemory/Database/TestContextEF6.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class TestContextEF6 : DbContext
1616
.AddConsole();
1717
});
1818

19-
public virtual DbSet<ProductDynamic> Products { get; set; }
19+
public virtual DbSet<ProductDynamic> Products { get; set; } = null!;
2020

2121
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2222
{
@@ -26,7 +26,6 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2626
optionsBuilder.UseInMemoryDatabase("TestContextEF6");
2727
}
2828

29-
3029
protected override void OnModelCreating(ModelBuilder modelBuilder)
3130
{
3231
modelBuilder
@@ -39,4 +38,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
3938
});
4039
}
4140
}
42-
}
41+
}

src-console/ConsoleAppEF6_InMemory/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@ static async Task Main(string[] args)
1717
{
1818
await using (var context = new TestContextEF6())
1919
{
20-
context.Products.Add(new ProductDynamic { NullableInt = 1, Dict = new Dictionary<string, object> { { "Name", "test" } } });
21-
context.Products.Add(new ProductDynamic { NullableInt = 2, Dict = new Dictionary<string, object> { { "Name1", "test1" } } });
20+
context.Products.Add(new ProductDynamic { NullableInt = 1, Key = 123, Dict = new Dictionary<string, object> { { "Name", "test" } } });
21+
context.Products.Add(new ProductDynamic { NullableInt = 2, Key = 456, Dict = new Dictionary<string, object> { { "Name1", "test1" } } });
2222
await context.SaveChangesAsync();
2323
}
2424

25+
// #784
26+
await using (var context = new TestContextEF6())
27+
{
28+
var result784 = context.Products.Where("NullableInt = @0", 1).ToDynamicArray<ProductDynamic>();
29+
Console.WriteLine("a1 {0}", string.Join(",", result784.Select(r => r.Key)));
30+
}
31+
2532
await using (var context = new TestContextEF6())
2633
{
2734
var intType = typeof(int).FullName;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<LangVersion>10</LangVersion>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Include="..\ConsoleAppEF2.0\Database\ProductDynamic.cs" Link="Database\ProductDynamic.cs" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.28" />
16+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
17+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore6.csproj" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using ConsoleAppEF2.Database;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace ConsoleApp_net6_0_EF6_Sqlite
7+
{
8+
public class TestContextEF6 : DbContext
9+
{
10+
public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder =>
11+
{
12+
builder
13+
.AddFilter("Default", LogLevel.Debug)
14+
.AddFilter("Microsoft", LogLevel.Debug)
15+
.AddFilter("System", LogLevel.Information)
16+
.AddConsole();
17+
});
18+
19+
public virtual DbSet<ProductDynamic> Products { get; set; } = null!;
20+
21+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
22+
{
23+
optionsBuilder.UseLoggerFactory(MyLoggerFactory); // Warning: Do not create a new ILoggerFactory instance each time
24+
optionsBuilder.EnableSensitiveDataLogging();
25+
26+
optionsBuilder.UseSqlite("Data Source=TestContextEF6.db");
27+
}
28+
29+
30+
protected override void OnModelCreating(ModelBuilder modelBuilder)
31+
{
32+
modelBuilder
33+
.Entity<ProductDynamic>()
34+
.OwnsOne(typeof(Dictionary<string, object>).Name, x => x.Dict, x =>
35+
{
36+
x.IndexerProperty<string>("Name").IsRequired(false);
37+
//x.IndexerProperty<string>("b").IsRequired(false);
38+
//x.Property<int?>("TestId").IsRequired(false);
39+
});
40+
}
41+
}
42+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)