Skip to content

Commit

Permalink
PredefinedTypesHelper: Fix loading types from System.Data.Entity and …
Browse files Browse the repository at this point in the history
…EntityFramework (#807)

* PredefinedTypesHelper: Fix loading types from System.Data.Entity and EntityFramework

* .

* type

* Add Demo

* .

* .

* bs

* 12

* 12test

* .

* .

* fs

* .
  • Loading branch information
StefH authored May 31, 2024
1 parent 2995cc8 commit 852434c
Show file tree
Hide file tree
Showing 29 changed files with 425 additions and 349 deletions.
72 changes: 55 additions & 17 deletions System.Linq.Dynamic.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeFirst.ConsoleApp", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeFirst.ConsoleApp8", "src-examples\CodeFirst.ConsoleApp8\CodeFirst.ConsoleApp8.csproj", "{68C7FF71-54F6-4D68-B419-65D1B10206D4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Host", "src-console\Demo.Host\Demo.Host.csproj", "{D8368319-F370-4071-9411-A3DADB234330}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Plugin", "src-console\Demo.Plugin\Demo.Plugin.csproj", "{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -869,6 +873,22 @@ Global
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x64.Build.0 = Release|Any CPU
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.ActiveCfg = Release|Any CPU
{51074A4C-15C2-4E72-81F2-2FC53903553B}.Release|x86.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.Build.0 = Release|Any CPU
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4}.Debug|ARM.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -917,22 +937,38 @@ Global
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x64.Build.0 = Release|Any CPU
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x86.ActiveCfg = Release|Any CPU
{68C7FF71-54F6-4D68-B419-65D1B10206D4}.Release|x86.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|ARM.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x64.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.ActiveCfg = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Debug|x86.Build.0 = Debug|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|Any CPU.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|ARM.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x64.Build.0 = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.ActiveCfg = Release|Any CPU
{CA03FD55-9DAB-4827-9A35-A96D3804B311}.Release|x86.Build.0 = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|ARM.ActiveCfg = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|ARM.Build.0 = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|x64.ActiveCfg = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|x64.Build.0 = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|x86.ActiveCfg = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Debug|x86.Build.0 = Debug|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|Any CPU.Build.0 = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|ARM.ActiveCfg = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|ARM.Build.0 = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|x64.ActiveCfg = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|x64.Build.0 = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|x86.ActiveCfg = Release|Any CPU
{D8368319-F370-4071-9411-A3DADB234330}.Release|x86.Build.0 = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|ARM.Build.0 = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|x64.Build.0 = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|x86.ActiveCfg = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Debug|x86.Build.0 = Debug|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|Any CPU.Build.0 = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|ARM.ActiveCfg = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|ARM.Build.0 = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x64.ActiveCfg = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x64.Build.0 = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x86.ActiveCfg = Release|Any CPU
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -982,10 +1018,12 @@ Global
{9000129D-322D-4FE6-9C47-75464577C374} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F}
{ABB1BF71-8927-49BB-99F3-70BCB2CD161E} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38}
{51074A4C-15C2-4E72-81F2-2FC53903553B} = {122BC4FA-7563-4E35-9D17-077F16F1629F}
{CA03FD55-9DAB-4827-9A35-A96D3804B311} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{E36D1A08-F3ED-48C7-9DBF-8F625974A6C4} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
{9E0D0994-7D84-40FF-8383-189F142FEF11} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
{68C7FF71-54F6-4D68-B419-65D1B10206D4} = {BCA2A024-9032-4E56-A6C4-17A15D921728}
{CA03FD55-9DAB-4827-9A35-A96D3804B311} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{D8368319-F370-4071-9411-A3DADB234330} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
13 changes: 8 additions & 5 deletions src-console/ConsoleApp_net452_EF6/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ class Program
{
static void Main(string[] args)
{
using (var context = new KendoGridDbContext())
var config = new ParsingConfig
{
var config = new ParsingConfig
{
UseParameterizedNamesInDynamicQuery = true
};
UseParameterizedNamesInDynamicQuery = true
};

var q = new[] { 1, 2, 3 }.AsQueryable();
var r = q.Where("it > 1").ToArray();

using (var context = new KendoGridDbContext())
{
var found1 = context.Employees.FirstOrDefault(config, "EmployeeNumber > 1000");
Console.WriteLine($"found1 : {found1.Id} - {found1.EmployeeNumber}");

Expand Down
21 changes: 21 additions & 0 deletions src-console/Demo.Host/Demo.Host.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<!--<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.13" />-->
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\System.Linq.Dynamic.Core\System.Linq.Dynamic.Core.csproj" />
</ItemGroup>

</Project>
66 changes: 66 additions & 0 deletions src-console/Demo.Host/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Dynamic.Core;
using System.Reflection;
using Serilog;
using Serilog.Exceptions;

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

Log.Logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss.fff} [{Level}] {Message}{NewLine}{Exception}")
.CreateLogger();

var customers = new List<Customer>
{
new(Guid.NewGuid(), [
new Order(Guid.NewGuid()),
new Order(Guid.NewGuid()),
new Order(Guid.NewGuid()),
new Order(Guid.NewGuid())
]),
new(Guid.NewGuid(), [
new Order(Guid.NewGuid()),
new Order(Guid.NewGuid())
])
};

Log.Information("--- LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = {load} ---", false);
var result = customers
.AsQueryable()
.Where("Orders.Count >= @0", 3)
.OrderBy("Orders.Count")
.ToList();
Log.Information("Found {Count} customers: {Customers}", result.Count, result);

Log.Information(new string('*', 80));

Log.Information("--- LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = {load} ---", true);
var config = new ParsingConfig
{
LoadAdditionalAssembliesFromCurrentDomainBaseDirectory = true
};
var result2 = customers
.AsQueryable()
.Where(config, "Orders.Count >= @0", 3)
.OrderBy("Orders.Count")
.ToList();
Log.Information("Found {Count} customers: {Customers}", result2.Count, result2);

return;

static Assembly? CurrentDomainOnAssemblyResolve(object? sender, ResolveEventArgs resolveEventArgs)
{
Log.Warning("Attempted to resolve assembly {Name} by {RequestingAssembly}", resolveEventArgs.Name, resolveEventArgs.RequestingAssembly?.GetName().Name);

return null;
}

[SuppressMessage("Design", "CA1050:Declare types in namespaces")]
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")]
public record Order(Guid Id);

[SuppressMessage("Design", "CA1050:Declare types in namespaces")]
[SuppressMessage("ReSharper", "NotAccessedPositionalProperty.Global")]
public record Customer(Guid Id, List<Order> Orders);
15 changes: 15 additions & 0 deletions src-console/Demo.Plugin/Demo.Plugin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<Target Name="CopyDllAfterBuild" AfterTargets="PostBuildEvent">
<Copy
SourceFiles="$(OutputPath)Demo.Plugin.dll"
DestinationFolder="../Demo.Host/bin/Debug/net8.0" />
</Target>

</Project>
9 changes: 9 additions & 0 deletions src-console/Demo.Plugin/MyPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Demo.Plugin;

public static class MyPlugin
{
public static void Print()
{
Console.WriteLine("Hello, World!");
}
}
15 changes: 15 additions & 0 deletions src-console/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if (Test-Path -Path ".\output") {
Remove-Item -Force -Recurse -Path ".\output\"
}
else {
New-Item -Path ".\output" -ItemType Directory
}


Write-Host "Build solution..."

dotnet build .\LinqCoreDemo.sln --nologo --configuration "Debug"

Write-Host "Publish projects..."
dotnet publish .\src\Demo.Plugin\Demo.Plugin.csproj --nologo --no-build --configuration "Debug" --output .\output
dotnet publish .\src\Demo.Host\Demo.Host.csproj --nologo --no-build --configuration "Debug" --output .\output
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Copyright>Copyright © ZZZ Projects</Copyright>
<DefaultLanguage>en-us</DefaultLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>PackageReadme.md</PackageReadmeFile>
Expand Down
8 changes: 8 additions & 0 deletions src/EntityFramework.DynamicLinq/EFType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EntityFramework.DynamicLinq;

/// <summary>
/// A dummy class to determine if the assembly is using EntityFramework.
/// </summary>
public struct EFType
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PackageTags>system;linq;dynamic;entityframework;core;async</PackageTags>
<ProjectGuid>{D3804228-91F4-4502-9595-39584E510000}</ProjectGuid>
<TargetFrameworks>net45;net452;net46;netstandard2.1</TargetFrameworks>
<LangVersion>10</LangVersion>
<Version>1.3.$(PatchVersion)</Version>
</PropertyGroup>

Expand Down
Loading

0 comments on commit 852434c

Please sign in to comment.