Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion System.Linq.Dynamic.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-console", "test-consol
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test-uap", "test-uap", "{ECA5702B-5D32-4888-A34E-9461FC533F23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp_netcore2.0_EF2.0.1", "src-console\ConsoleAppEF2.0\ConsoleApp_netcore2.0_EF2.0.1.csproj", "{60CE11E0-E057-45A2-8F8A-73B1BD045BFB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore2.0_EF2.0.1", "src-console\ConsoleAppEF2.0\ConsoleApp_netcore2.0_EF2.0.1.csproj", "{60CE11E0-E057-45A2-8F8A-73B1BD045BFB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore1.1_EF1.1.2", "src-console\ConsoleAppEF1.1\ConsoleApp_netcore1.1_EF1.1.2.csproj", "{59E67CE3-5DB7-4D37-B308-E4E22E3DE4F4}"
EndProject
Expand All @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp_net40_sqlite", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp_net452_EF6", "src-console\ConsoleApp_net452_EF6\ConsoleApp_net452_EF6.csproj", "{5DC68E83-ABE0-4887-B17E-1ED4EEE89C2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_netcore2.0_EF2.0.2_InMemory", "src-console\ConsoleAppEF2.0.2_InMemory\ConsoleApp_netcore2.0_EF2.0.2_InMemory.csproj", "{437473EE-7FBB-4C28-96EC-41E1AEE161F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -251,6 +253,22 @@ Global
{5DC68E83-ABE0-4887-B17E-1ED4EEE89C2C}.Release|x64.Build.0 = Release|Any CPU
{5DC68E83-ABE0-4887-B17E-1ED4EEE89C2C}.Release|x86.ActiveCfg = Release|Any CPU
{5DC68E83-ABE0-4887-B17E-1ED4EEE89C2C}.Release|x86.Build.0 = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|ARM.ActiveCfg = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|ARM.Build.0 = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|x64.ActiveCfg = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|x64.Build.0 = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|x86.ActiveCfg = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Debug|x86.Build.0 = Debug|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|Any CPU.Build.0 = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|ARM.ActiveCfg = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|ARM.Build.0 = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|x64.ActiveCfg = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|x64.Build.0 = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|x86.ActiveCfg = Release|Any CPU
{437473EE-7FBB-4C28-96EC-41E1AEE161F3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -268,6 +286,7 @@ Global
{0EB12661-F5CF-4071-9812-F4C8AF3D4531} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{E587974C-19A9-426A-A952-216D5F883EB6} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{5DC68E83-ABE0-4887-B17E-1ED4EEE89C2C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62}
{437473EE-7FBB-4C28-96EC-41E1AEE161F3} = {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
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>ConsoleAppEF2</AssemblyName>
<RootNamespace>ConsoleAppEF2</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.EntityFrameworkCore.DynamicLinq\Microsoft.EntityFrameworkCore.DynamicLinq.csproj" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions src-console/ConsoleAppEF2.0.2_InMemory/Database/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;

namespace ConsoleAppEF2.Database
{
public class Car
{
[Key]
public int Key { get; set; }

[Required]
[StringLength(8)]
public string Vin { get; set; }

[Required]
public string Year { get; set; }

[Required]
public string Brand { get; set; }

[Required]
public string Color { get; set; }
}
}
22 changes: 22 additions & 0 deletions src-console/ConsoleAppEF2.0.2_InMemory/Database/TestContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;

namespace ConsoleAppEF2.Database
{
public class TestContext : DbContext
{
public virtual DbSet<Car> Cars { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseInMemoryDatabase("cars");
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Car>().HasKey(c => c.Key);
}

// https://stackoverflow.com/questions/46212704/how-do-i-write-ef-functions-extension-method
public static bool Like(string matchExpression, string pattern) => EF.Functions.Like(matchExpression, pattern);
}
}
119 changes: 119 additions & 0 deletions src-console/ConsoleAppEF2.0.2_InMemory/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Dynamic.Core.CustomTypeProviders;
using ConsoleAppEF2.Database;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;

namespace ConsoleAppEF2
{
class Program
{
class C : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
{
public HashSet<Type> GetCustomTypes()
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();

var set = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies))
{
typeof(TestContext)
};

return set;
}
}

private static IQueryable GetQueryable()
{
var random = new Random((int)DateTime.Now.Ticks);

var x = Enumerable.Range(0, 10).Select(i => new
{
Id = i,
Value = random.Next(),
});

return x.AsQueryable().Select("new (it as Id, @0 as Value)", random.Next());
// return x.AsQueryable(); //x.AsQueryable().Select("new (Id, Value)");
}

static void Main(string[] args)
{
IQueryable qry = GetQueryable();

var result = qry.Select("it").OrderBy("Value");
try
{
Console.WriteLine("result {0}", JsonConvert.SerializeObject(result, Formatting.Indented));
}
catch (Exception)
{
// Console.WriteLine(e);
}

var all = new
{
test1 = new List<int> { 1, 2, 3 }.ToDynamicList(typeof(int)),
test2 = new List<dynamic> { 4, 5, 6 }.ToDynamicList(typeof(int)),
test3 = new List<object> { 7, 8, 9 }.ToDynamicList(typeof(int))
};
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));

var config = new ParsingConfig
{
CustomTypeProvider = new C()
};

var context = new TestContext();
context.Cars.Add(new Car { Brand = "Ford", Color = "Blue", Vin = "yes", Year = "2017" });
context.Cars.Add(new Car { Brand = "Fiat", Color = "Red", Vin = "yes", Year = "2016" });
context.Cars.Add(new Car { Brand = "Alfa", Color = "Black", Vin = "no", Year = "1979" });
context.Cars.Add(new Car { Brand = "Alfa", Color = "Black", Vin = "a%bc", Year = "1979" });
context.SaveChanges();

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 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 dynamicCarsLike2 = context.Cars.Where(config, "TestContext.Like(Brand, \"%d%\")");
Console.WriteLine("dynamicCarsLike2 {0}", JsonConvert.SerializeObject(dynamicCarsLike2, Formatting.Indented));

var dynamicFunctionsLike1 = context.Cars.Where(config, "DynamicFunctions.Like(Brand, \"%a%\")");
Console.WriteLine("dynamicFunctionsLike1 {0}", JsonConvert.SerializeObject(dynamicFunctionsLike1, 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
{
K = c.Key,
C = c.Color
});

var testDynamicResult = testDynamic.Select("it").OrderBy("C");
try
{
Console.WriteLine("resultX {0}", JsonConvert.SerializeObject(testDynamicResult, Formatting.Indented));
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
4 changes: 2 additions & 2 deletions src-console/ConsoleAppEF2.0/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ static void Main(string[] args)
{
Console.WriteLine("result {0}", JsonConvert.SerializeObject(result, Formatting.Indented));
}
catch (Exception e)
catch (Exception)
{
Console.WriteLine(e);
// Console.WriteLine(e);
}

var all = new
Expand Down
Loading