Skip to content

Commit

Permalink
PredefinedTypesHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Jul 29, 2018
1 parent f1cfbe2 commit e0e0b99
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 139 deletions.
38 changes: 22 additions & 16 deletions src-console/ConsoleAppEF2.0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public HashSet<Type> GetCustomTypes()

set.Add(typeof(TestContext));

//set.Add(typeof(DbFunctionsExtensions));
//set.Add(typeof(EF));

return set;
}
}
Expand Down Expand Up @@ -82,26 +85,29 @@ static void Main(string[] args)
var carFirstOrDefault = context.Cars.Where(config, "Brand == \"Ford\"");
Console.WriteLine("carFirstOrDefault {0}", JsonConvert.SerializeObject(carFirstOrDefault, Formatting.Indented));

var carsLike1 =
from c in context.Cars
where EF.Functions.Like(c.Brand, "%a%")
select c;
Console.WriteLine("carsLike1 {0}", JsonConvert.SerializeObject(carsLike1, Formatting.Indented));
//var carsLike1 =
// from c in context.Cars
// where EF.Functions.Like(c.Brand, "%a%")
// select c;
//Console.WriteLine("carsLike1 {0}", JsonConvert.SerializeObject(carsLike1, Formatting.Indented));

//var cars2Like = context.Cars.Where(c => EF.Functions.Like(c.Brand, "%a%"));
//Console.WriteLine("cars2Like {0}", JsonConvert.SerializeObject(cars2Like, Formatting.Indented));

var cars2Like = context.Cars.Where(c => EF.Functions.Like(c.Brand, "%a%"));
Console.WriteLine("cars2Like {0}", JsonConvert.SerializeObject(cars2Like, Formatting.Indented));
//var dynamicCarsLike1 = context.Cars.Where(config, "TestContext.Like(Brand, \"%a%\")");
//Console.WriteLine("dynamicCarsLike1 {0}", JsonConvert.SerializeObject(dynamicCarsLike1, Formatting.Indented));

var dynamicCarsLike1 = context.Cars.Where(config, "TestContext.Like(Brand, \"%a%\")");
Console.WriteLine("dynamicCarsLike1 {0}", JsonConvert.SerializeObject(dynamicCarsLike1, Formatting.Indented));
//var dynamicCarsLike2 = context.Cars.Where(config, "TestContext.Like(Brand, \"%d%\")");
//Console.WriteLine("dynamicCarsLike2 {0}", JsonConvert.SerializeObject(dynamicCarsLike2, Formatting.Indented));

var dynamicCarsLike2 = context.Cars.Where(config, "TestContext.Like(Brand, \"%d%\")");
Console.WriteLine("dynamicCarsLike2 {0}", JsonConvert.SerializeObject(dynamicCarsLike2, Formatting.Indented));
var dynamicFunctionsLikeExecutedLocal = context.Cars.Where(config, "DynamicFunctions.Like(Brand, \"%a%\")");
Console.WriteLine("dynamicFunctionsLikeExecutedLocal {0}", JsonConvert.SerializeObject(dynamicFunctionsLikeExecutedLocal, Formatting.Indented));

var dynamicFunctionsLike1 = context.Cars.Where(config, "DynamicFunctions.Like(Brand, \"%a%\")");
Console.WriteLine("dynamicFunctionsLike1 {0}", JsonConvert.SerializeObject(dynamicFunctionsLike1, Formatting.Indented));
var dynamicFunctionsLikeExecutedOnServer = context.Cars.Where(config, "DbFunctionsExtensions.Like(EF.Functions, Brand, \"%a%\")");
Console.WriteLine("dynamicFunctionsLikeExecutedOnServer {0}", JsonConvert.SerializeObject(dynamicFunctionsLikeExecutedOnServer, Formatting.Indented));

var dynamicFunctionsLike2 = context.Cars.Where(config, "DynamicFunctions.Like(Vin, \"%a.%b%\", \".\")");
Console.WriteLine("dynamicFunctionsLike2 {0}", JsonConvert.SerializeObject(dynamicFunctionsLike2, Formatting.Indented));
//var dynamicFunctionsLike2 = context.Cars.Where(config, "DynamicFunctions.Like(Vin, \"%a.%b%\", \".\")");
//Console.WriteLine("dynamicFunctionsLike2 {0}", JsonConvert.SerializeObject(dynamicFunctionsLike2, Formatting.Indented));

var testDynamic = context.Cars.Select(c => new
{
Expand All @@ -112,7 +118,7 @@ where EF.Functions.Like(c.Brand, "%a%")
var testDynamicResult = testDynamic.Select("it").OrderBy("C");
try
{
Console.WriteLine("resultX {0}", JsonConvert.SerializeObject(testDynamicResult, Formatting.Indented));
Console.WriteLine("testDynamicResult {0}", JsonConvert.SerializeObject(testDynamicResult, Formatting.Indented));
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<Compile Include="..\ConsoleAppEF2.0\Database\Car.cs" Link="Database\Car.cs" />
<Compile Include="..\ConsoleAppEF2.0\Database\TestContext.cs" Link="Database\TestContext.cs" />
<Compile Include="..\ConsoleAppEF2.0\Program.cs" Link="Program.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
123 changes: 0 additions & 123 deletions src-console/ConsoleAppEF2.1.1/Program.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ static PredefinedTypesHelper()
TryAdd("System.Data.Entity.SqlServer.SqlSpatialFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 2);
#endif

#if NETSTANDARD
// Try to add DbFunctionsExtensions and EF from EF Core 2 or higher
TryAdd("Microsoft.EntityFrameworkCore.DbFunctionsExtensions, Microsoft.EntityFrameworkCore", 4);
TryAdd("Microsoft.EntityFrameworkCore.EF, Microsoft.EntityFrameworkCore", 4);
#endif

#if NETSTANDARD2_0
TryAdd("Microsoft.EntityFrameworkCore.DynamicLinq.DynamicFunctions, Microsoft.EntityFrameworkCore.DynamicLinq, Version=1.0.0.0, Culture=neutral, PublicKeyToken=974e7e1b462f3693", 3);
#endif
Expand Down

0 comments on commit e0e0b99

Please sign in to comment.