diff --git a/src/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore3/EFCoreType.cs b/src/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore3/EFCoreType.cs new file mode 100644 index 00000000..d2d82539 --- /dev/null +++ b/src/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore3/EFCoreType.cs @@ -0,0 +1,8 @@ +namespace Microsoft.EntityFrameworkCore.DynamicLinq; + +/// +/// A dummy class to determine if the assembly is using EF Core. +/// +public struct EFCoreType +{ +} \ No newline at end of file diff --git a/src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs b/src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs index 95cca807..4c52143a 100644 --- a/src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs +++ b/src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs @@ -6,9 +6,8 @@ namespace System.Linq.Dynamic.Core.Parser; internal static class PredefinedTypesHelper { -#if NETSTANDARD2_0 + private const string PublicKeyToken = "974e7e1b462f3693"; private static readonly string Version = Text.RegularExpressions.Regex.Match(typeof(PredefinedTypesHelper).AssemblyQualifiedName!, @"\d+\.\d+\.\d+\.\d+").ToString(); -#endif // These shorthands have different name than actual type and therefore not recognized by default from the PredefinedTypes. public static readonly IDictionary PredefinedTypesShorthands = new Dictionary @@ -75,24 +74,25 @@ static PredefinedTypesHelper() TryAdd("System.Data.Entity.SqlServer.SqlSpatialFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 2); } -#if NETSTANDARD2_0 - TryAdd($"Microsoft.EntityFrameworkCore.DynamicLinq.DynamicFunctions, Microsoft.EntityFrameworkCore.DynamicLinq, Version={Version}, Culture=neutral, PublicKeyToken=974e7e1b462f3693", 3); -#endif + if (Type.GetType($"Microsoft.EntityFrameworkCore.DynamicLinq.EFType, Microsoft.EntityFrameworkCore.DynamicLinq, Version={Version}, Culture=neutral, PublicKeyToken={PublicKeyToken}") != null) + { + TryAdd($"Microsoft.EntityFrameworkCore.DynamicLinq.DynamicFunctions, Microsoft.EntityFrameworkCore.DynamicLinq, Version={Version}, Culture=neutral, PublicKeyToken={PublicKeyToken}", 3); + } } private static void TryAdd(string typeName, int x) { try { - var efType = Type.GetType(typeName); - if (efType != null) + var type = Type.GetType(typeName); + if (type != null) { - PredefinedTypes.Add(efType, x); + PredefinedTypes.Add(type, x); } } catch { - // in case of exception, do not add + // In case of exception, do not add } }