diff --git a/.gitignore b/.gitignore index 8e6f9f1..c96a87f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,236 @@ -*.[Rr]e[Ss]harper -*[Rr]e[Ss]harper.user -_[Rr]e[Ss]harper.*/ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates -[Ss]tyle[Cc]op.[Cc]ache +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +# Build results [Dd]ebug/ +[Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ [Bb]in/ [Oo]bj/ -[Bb]uild/ -[Dd]ist/ -[Cc]lient[Bb]in/ -[Pp]ublish/ -[Pp]ackages/ + +# Visual Studio 2015 cache/options directory .vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ -*.suo -*.sln.cache -*.user -*.vssscc +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log *.vspscc -*.[Pp]ublish.xml +*.vssscc +.builds +*.pidb +*.svclog +*.scc -[Tt]est[Rr]esults/ -[Tt]est[Rr]esult.xml +# Chutzpah Test files +_Chutzpah* -*.dotCover -*.ndproj -/NDependOut -.idea -.dbshell -*.vspx +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler *.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages *.nupkg -*/*.ide/* +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Microsoft Azure ApplicationInsights config file +ApplicationInsights.config + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ diff --git a/LinqKit Solution.sln b/LinqKit Solution.sln new file mode 100644 index 0000000..6265b91 --- /dev/null +++ b/LinqKit Solution.sln @@ -0,0 +1,81 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2F7F283D-5576-417F-A467-EC210226AC3B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9FC09568-C879-47D8-9D28-E736B8A84C95}" + ProjectSection(SolutionItems) = preProject + global.json = global.json + README.md = README.md + EndProjectSection +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LinqKit.EntityFramework", "src-dotnet-core\LinqKit.EntityFramework\LinqKit.EntityFramework.xproj", "{CFF0D30F-9AF2-4F3D-8458-167C5CC430FD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src-original", "src-original", "{BF05142E-19C4-4359-9AAF-7A4EC2F27942}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqKit", "src\LinqKit.csproj", "{AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqKit.Net35", "src\LinqKit.Net35.csproj", "{E6DA2678-2910-4EA4-B9F8-180E6BFD87B0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{0BE21A11-8EF0-404B-AFC0-533A62386C4C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{4521E792-157C-4049-ADF0-CDA31EFC3CC7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "src\Demo\Demo.csproj", "{AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqKit.Tests", "src\Tests\LinqKit.Tests.csproj", "{A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LinqKit.Microsoft.EntityFrameworkCore", "src-dotnet-core\LinqKit.Microsoft.EntityFrameworkCore\LinqKit.Microsoft.EntityFrameworkCore.xproj", "{F9861A91-C2E4-4D20-B486-89272898FE23}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LinqKit", "src-dotnet-core\LinqKit\LinqKit.xproj", "{667345EE-B154-432F-A908-CB6374805C20}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CFF0D30F-9AF2-4F3D-8458-167C5CC430FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CFF0D30F-9AF2-4F3D-8458-167C5CC430FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CFF0D30F-9AF2-4F3D-8458-167C5CC430FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CFF0D30F-9AF2-4F3D-8458-167C5CC430FD}.Release|Any CPU.Build.0 = Release|Any CPU + {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6}.Release|Any CPU.Build.0 = Release|Any CPU + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0}.Release|Any CPU.Build.0 = Release|Any CPU + {AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3}.Release|Any CPU.Build.0 = Release|Any CPU + {A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09}.Release|Any CPU.Build.0 = Release|Any CPU + {F9861A91-C2E4-4D20-B486-89272898FE23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9861A91-C2E4-4D20-B486-89272898FE23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9861A91-C2E4-4D20-B486-89272898FE23}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9861A91-C2E4-4D20-B486-89272898FE23}.Release|Any CPU.Build.0 = Release|Any CPU + {667345EE-B154-432F-A908-CB6374805C20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {667345EE-B154-432F-A908-CB6374805C20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {667345EE-B154-432F-A908-CB6374805C20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {667345EE-B154-432F-A908-CB6374805C20}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {CFF0D30F-9AF2-4F3D-8458-167C5CC430FD} = {2F7F283D-5576-417F-A467-EC210226AC3B} + {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6} = {BF05142E-19C4-4359-9AAF-7A4EC2F27942} + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0} = {BF05142E-19C4-4359-9AAF-7A4EC2F27942} + {AA8FD6A3-D1D1-49B6-8ED4-388E94E4F2F3} = {4521E792-157C-4049-ADF0-CDA31EFC3CC7} + {A8A8E0D9-CC31-4B84-9ED2-2B808C9F0B09} = {0BE21A11-8EF0-404B-AFC0-533A62386C4C} + {F9861A91-C2E4-4D20-B486-89272898FE23} = {2F7F283D-5576-417F-A467-EC210226AC3B} + {667345EE-B154-432F-A908-CB6374805C20} = {2F7F283D-5576-417F-A467-EC210226AC3B} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index c47b084..ad87f53 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -[![Build status](https://ci.appveyor.com/api/projects/status/github/scottksmith95/LINQKit)](https://ci.appveyor.com/project/Thorium/linqkit) +[![Build status](https://ci.appveyor.com/api/projects/status/0c4v2bsvdqd57600?svg=true)](https://ci.appveyor.com/project/StefH/system-linq-dynamic-core) + +EntityFramework.LinqKit +[![Version](https://img.shields.io/nuget/v/EntityFramework.LinqKit.svg)](https://www.nuget.org/packages/EntityFramework.LinqKit) + +Microsoft.EntityFrameworkCore.LinqKit +[![Version](https://img.shields.io/nuget/v/Microsoft.EntityFrameworkCore.LinqKit.svg)](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.LinqKit) What is LINQKit? ======= diff --git a/global.json b/global.json new file mode 100644 index 0000000..b51e28b --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "projects": [ "src", "test" ], + "sdk": { + "version": "1.0.0-preview1-002702" + } +} diff --git a/src-dotnet-core/LinqKit.EntityFramework/LinqKit.EntityFramework.xproj b/src-dotnet-core/LinqKit.EntityFramework/LinqKit.EntityFramework.xproj new file mode 100644 index 0000000..560a3af --- /dev/null +++ b/src-dotnet-core/LinqKit.EntityFramework/LinqKit.EntityFramework.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + cff0d30f-9af2-4f3d-8458-167c5cc430fd + LINQKit + .\obj + .\bin\ + v4.5.2 + + + + 2.0 + + + diff --git a/src-dotnet-core/LinqKit.EntityFramework/Properties/AssemblyInfo.cs b/src-dotnet-core/LinqKit.EntityFramework/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..14a4773 --- /dev/null +++ b/src-dotnet-core/LinqKit.EntityFramework/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("LinqKit")] +[assembly: AssemblyProduct("LinqKit")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cff0d30f-9af2-4f3d-8458-167c5cc430fd")] diff --git a/src-dotnet-core/LinqKit.EntityFramework/_build nuget.cmd b/src-dotnet-core/LinqKit.EntityFramework/_build nuget.cmd new file mode 100644 index 0000000..f642db5 --- /dev/null +++ b/src-dotnet-core/LinqKit.EntityFramework/_build nuget.cmd @@ -0,0 +1,3 @@ +dotnet restore +dotnet pack -c Release project.json +pause \ No newline at end of file diff --git a/src-dotnet-core/LinqKit.EntityFramework/project.json b/src-dotnet-core/LinqKit.EntityFramework/project.json new file mode 100644 index 0000000..5e080ce --- /dev/null +++ b/src-dotnet-core/LinqKit.EntityFramework/project.json @@ -0,0 +1,82 @@ +{ + "version": "1.0.0.0", + "title": "LinqKit for EntityFramework (with IAsync support)", + "description": "LinqKit.EntityFramework is a free set of extensions for LINQ to SQL and Entity Framework power users. (IAsync supported)", + "authors": [ "Joseph Albahari", "Tomas Petricek", "Scott Smith", "Stef Heyenrath" ], + + "packOptions": { + "summary": "LinqKit.EntityFramework is a free set of extensions for LINQ to SQL and Entity Framework power users. (IAsync supported)", + "tags": [ "linq", "EF", "EntityFramework", "Entity", "Framework" ], + "owners": [ "Stef Heyenrath" ], + "repository": { + "type": "git", + "url": "https://github.com/StefH/LINQKit" + }, + "projectUrl": "https://github.com/StefH/LINQKit", + "licenseUrl": "https://raw.githubusercontent.com/StefH/LINQKit/master/src/license.txt", + "releaseNotes": "dotnet rc2" + }, + + "buildOptions": { + "xmlDoc": true, + "define": [ "EF" ], + "compile": { + "include": [ + "../../src/*.cs" + ] + } + }, + + "dependencies": { + "JetBrains.Annotations": { + "version": "10.1.4", + "type": "build" + } + }, + + "frameworks": { + "net35": { + "frameworkAssemblies": { + } + }, + "net40": { + "frameworkAssemblies": { + } + }, + "net45": { + "frameworkAssemblies": { + }, + "dependencies": { + "EntityFramework": "6.1.3" + } + }, + "net451": { + "frameworkAssemblies": { + }, + "dependencies": { + "EntityFramework": "6.1.3" + } + }, + "net452": { + "frameworkAssemblies": { + }, + "dependencies": { + "EntityFramework": "6.1.3" + } + }, + "net46": { + "frameworkAssemblies": { + }, + "dependencies": { + "EntityFramework": "6.1.3" + } + }, + "net461": { + "frameworkAssemblies": { + }, + "dependencies": { + "EntityFramework": "6.1.3" + } + } + } +} \ No newline at end of file diff --git a/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/LinqKit.Microsoft.EntityFrameworkCore.xproj b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/LinqKit.Microsoft.EntityFrameworkCore.xproj new file mode 100644 index 0000000..6681990 --- /dev/null +++ b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/LinqKit.Microsoft.EntityFrameworkCore.xproj @@ -0,0 +1,19 @@ + + + + 14.0.25123 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + f9861a91-c2e4-4d20-b486-89272898fe23 + Microsoft.EntityFrameworkCore.LinqKit + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/Properties/AssemblyInfo.cs b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..14a4773 --- /dev/null +++ b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("LinqKit")] +[assembly: AssemblyProduct("LinqKit")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cff0d30f-9af2-4f3d-8458-167c5cc430fd")] diff --git a/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/_build nuget.cmd b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/_build nuget.cmd new file mode 100644 index 0000000..f642db5 --- /dev/null +++ b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/_build nuget.cmd @@ -0,0 +1,3 @@ +dotnet restore +dotnet pack -c Release project.json +pause \ No newline at end of file diff --git a/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/project.json b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/project.json new file mode 100644 index 0000000..e6a51f1 --- /dev/null +++ b/src-dotnet-core/LinqKit.Microsoft.EntityFrameworkCore/project.json @@ -0,0 +1,91 @@ +{ + "version": "1.0.0.0", + "title": "LinqKit for Microsoft.EntityFrameworkCore (with IDbAsync support)", + "description": "LinqKit.Microsoft.EntityFrameworkCore is a free set of extensions for LINQ to SQL and EntityFrameworkCore power users. (IDbAsync supported)", + "authors": [ "Joseph Albahari", "Tomas Petricek", "Scott Smith", "Stef Heyenrath" ], + + "packOptions": { + "summary": "LinqKit.Microsoft.EntityFrameworkCore is a free set of extensions for LINQ to SQL and EntityFrameworkCore power users. (IDbAsync supported)", + "tags": [ "linq", "EF", "EntityFramework", "Entity", "Framework", "Core" ], + "owners": [ "Stef Heyenrath" ], + "repository": { + "type": "git", + "url": "https://github.com/StefH/LINQKit" + }, + "projectUrl": "https://github.com/StefH/LINQKit", + "licenseUrl": "https://raw.githubusercontent.com/StefH/LINQKit/master/src/license.txt", + "releaseNotes": "dotnet rc2" + }, + + "buildOptions": { + "xmlDoc": true, + "define": [ "EFCORE" ], + "compile": { + "include": [ + "../../src/*.cs" + ] + } + }, + + "dependencies": { + "JetBrains.Annotations": { + "version": "10.1.4", + "type": "build" + }, + "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final" + }, + + "frameworks": { + "net451": { + "frameworkAssemblies": { + } + }, + "net452": { + "frameworkAssemblies": { + } + }, + "net46": { + "frameworkAssemblies": { + } + }, + "net461": { + "frameworkAssemblies": { + } + }, + "dnx451": { + "frameworkAssemblies": { + } + }, + "netcore50": { + "buildOptions": { "define": [ "WINDOWS_APP" ] }, + "dependencies": { + "NETStandard.Library": { + "version": "1.5.0-rc2-24027" + }, + "System.Threading.Tasks": "4.0.11-rc2-24027" + } + }, + "netstandard1.3": { + "buildOptions": { "define": [ "NETSTANDARD" ] }, + "NETStandard.Library": { + "version": "1.5.0-rc2-24027" + }, + "imports": [ + "portable-win81+wp81", + "portable-net45+wp8", + "portable-net45+win8+wp8", + "portable-wp81+wpa81", + "portable-win81+wp81+wpa81", + "portable-net45+win8+wpa81+wp8", + "portable-net45+win8", + "portable-net45+win8+wpa81", + "portable-win81+wpa81", + "portable-net451+win81", + "portable-net451+win81+wpa81" + ], + "dependencies": { + "System.Threading.Tasks": "4.0.11-rc2-24027" + } + } + } +} \ No newline at end of file diff --git a/src-dotnet-core/LinqKit/LinqKit.xproj b/src-dotnet-core/LinqKit/LinqKit.xproj new file mode 100644 index 0000000..927132f --- /dev/null +++ b/src-dotnet-core/LinqKit/LinqKit.xproj @@ -0,0 +1,19 @@ + + + + 14.0.25123 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 667345ee-b154-432f-a908-cb6374805c20 + LinqKit + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/src-dotnet-core/LinqKit/Properties/AssemblyInfo.cs b/src-dotnet-core/LinqKit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3a077e9 --- /dev/null +++ b/src-dotnet-core/LinqKit/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("LinqKit")] +[assembly: AssemblyProduct("LinqKit")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +#if !NETSTANDARD +[assembly: Guid("cff0d30f-9af2-4f3d-8458-167c5cc4aaaa")] +#endif \ No newline at end of file diff --git a/src-dotnet-core/LinqKit/_build nuget.cmd b/src-dotnet-core/LinqKit/_build nuget.cmd new file mode 100644 index 0000000..f642db5 --- /dev/null +++ b/src-dotnet-core/LinqKit/_build nuget.cmd @@ -0,0 +1,3 @@ +dotnet restore +dotnet pack -c Release project.json +pause \ No newline at end of file diff --git a/src-dotnet-core/LinqKit/project.json b/src-dotnet-core/LinqKit/project.json new file mode 100644 index 0000000..b76a76c --- /dev/null +++ b/src-dotnet-core/LinqKit/project.json @@ -0,0 +1,116 @@ +{ + "version": "1.0.0.0", + "title": "LinqKit", + "description": "LinqKit is a free set of extensions for LINQ to SQL and Entity Framework power users.", + "authors": [ "Joseph Albahari", "Tomas Petricek", "Scott Smith", "Stef Heyenrath" ], + + "packOptions": { + "summary": "EntityFramework.LinqKit is a free set of extensions for LINQ to SQL and Entity Framework power users.", + "tags": [ "linq", "EF", "EntityFramework", "Entity", "Framework" ], + "owners": [ "Stef Heyenrath" ], + "repository": { + "type": "git", + "url": "https://github.com/StefH/LINQKit" + }, + "projectUrl": "https://github.com/StefH/LINQKit", + "licenseUrl": "https://raw.githubusercontent.com/StefH/LINQKit/master/src/license.txt", + "releaseNotes": "dotnet rc2" + }, + + "buildOptions": { + "xmlDoc": true, + "define": [ "NOEF" ], + "compile": { + "include": [ + "../../src/*.cs" + ] + } + }, + + "dependencies": { + "JetBrains.Annotations": { + "version": "10.1.4", + "type": "build" + } + }, + + "frameworks": { + "net35": { + "frameworkAssemblies": { + } + }, + "net40": { + "frameworkAssemblies": { + } + }, + "net45": { + "frameworkAssemblies": { + }, + "dependencies": { + } + }, + "net451": { + "frameworkAssemblies": { + }, + "dependencies": { + } + }, + "net452": { + "frameworkAssemblies": { + }, + "dependencies": { + } + }, + "net46": { + "frameworkAssemblies": { + }, + "dependencies": { + } + }, + "net461": { + "frameworkAssemblies": { + }, + "dependencies": { + } + }, + "netcore50": { + "buildOptions": { "define": [ "WINDOWS_APP" ] }, + "dependencies": { + "NETStandard.Library": { + "version": "1.5.0-rc2-24027" + }, + "System.Reflection.Extensions": "4.0.1-rc2-24027", + "System.Reflection.TypeExtensions": "4.1.0-rc2-24027", + "System.Linq.Queryable": "4.0.1-rc2-24027", + "System.Linq.Expressions": "4.0.11-rc2-24027", + "System.Threading.Tasks": "4.0.11-rc2-24027" + } + }, + "netstandard1.3": { + "buildOptions": { "define": [ "NETSTANDARD" ] }, + "NETStandard.Library": { + "version": "1.5.0-rc2-24027" + }, + "imports": [ + "portable-win81+wp81", + "portable-net45+wp8", + "portable-net45+win8+wp8", + "portable-wp81+wpa81", + "portable-win81+wp81+wpa81", + "portable-net45+win8+wpa81+wp8", + "portable-net45+win8", + "portable-net45+win8+wpa81", + "portable-win81+wpa81", + "portable-net451+win81", + "portable-net451+win81+wpa81" + ], + "dependencies": { + "System.Reflection.Extensions": "4.0.1-rc2-24027", + "System.Reflection.TypeExtensions": "4.1.0-rc2-24027", + "System.Linq.Queryable": "4.0.1-rc2-24027", + "System.Linq.Expressions": "4.0.11-rc2-24027", + "System.Threading.Tasks": "4.0.11-rc2-24027" + } + } + } +} \ No newline at end of file diff --git a/src-dotnet-core/_build nuget.cmd b/src-dotnet-core/_build nuget.cmd new file mode 100644 index 0000000..d86d3ad --- /dev/null +++ b/src-dotnet-core/_build nuget.cmd @@ -0,0 +1,5 @@ +dotnet restore +dotnet pack -c Release LinqKit\project.json +dotnet pack -c Release LinqKit.EntityFramework\project.json +dotnet pack -c Release LinqKit.Microsoft.EntityFrameworkCore\project.json +pause \ No newline at end of file diff --git a/src/AggregateBalanced.cs b/src/AggregateBalanced.cs index 1a9883d..aedcf13 100644 --- a/src/AggregateBalanced.cs +++ b/src/AggregateBalanced.cs @@ -1,11 +1,5 @@ -using System; -using System.Reflection; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Runtime.CompilerServices; +#if !(NET35 || NET40) using System.Linq.Expressions; -using System.Linq; namespace System.Linq { @@ -106,4 +100,5 @@ public static async System.Threading.Tasks.Task> AggregateBalanced } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/App.config b/src/App.config index f8df59f..3f770d6 100644 --- a/src/App.config +++ b/src/App.config @@ -2,8 +2,8 @@
- - + + diff --git a/src/ExpandableDbAsyncEnumerator.cs b/src/ExpandableDbAsyncEnumerator.cs index 3e234d8..7eaa32c 100644 --- a/src/ExpandableDbAsyncEnumerator.cs +++ b/src/ExpandableDbAsyncEnumerator.cs @@ -1,16 +1,24 @@ -using System; +#if !(NET35 || NET40 || NOEF) +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#if EF +using System.Data.Entity.Infrastructure; +#endif namespace LinqKit { - using System.Collections.Generic; - using System.Data.Entity.Infrastructure; - using System.Threading; - using System.Threading.Tasks; - /// Class for async-await style list enumeration support (e.g. .ToListAsync()) - public sealed class ExpandableDbAsyncEnumerator : IDbAsyncEnumerator, IDisposable + public sealed class ExpandableDbAsyncEnumerator : IDisposable, +#if EFCORE + IAsyncEnumerator +#else + IDbAsyncEnumerator +#endif { private readonly IEnumerator _inner; + /// Class for async-await style list enumeration support (e.g. .ToListAsync()) public ExpandableDbAsyncEnumerator(IEnumerator inner) { @@ -22,20 +30,31 @@ public void Dispose() { _inner.Dispose(); } + /// Enumerator-pattern: MoveNext public Task MoveNextAsync(CancellationToken cancellationToken) { return Task.FromResult(_inner.MoveNext()); } +#if EFCORE + public Task MoveNext(CancellationToken cancellationToken) + { + return Task.FromResult(_inner.MoveNext()); + } +#endif /// Enumerator-pattern: Current item public T Current { get { return _inner.Current; } } + +#if !EFCORE object IDbAsyncEnumerator.Current { get { return Current; } } +#endif } } +#endif \ No newline at end of file diff --git a/src/ExpandableQuery.cs b/src/ExpandableQuery.cs index 201010f..54c2979 100644 --- a/src/ExpandableQuery.cs +++ b/src/ExpandableQuery.cs @@ -3,11 +3,17 @@ using System.Linq; using System.Linq.Expressions; using System.Collections; -#if !NET35 + +#if !(NET35 || NET40 || NOEF) using System.Threading; +using System.Threading.Tasks; +#if EFCORE +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Query.Internal; +#else using System.Data.Entity; using System.Data.Entity.Infrastructure; -using System.Threading.Tasks; +#endif #endif namespace LinqKit @@ -16,8 +22,10 @@ namespace LinqKit /// An IQueryable wrapper that allows us to visit the query's expression tree just before LINQ to SQL gets to it. /// This is based on the excellent work of Tomas Petricek: http://tomasp.net/blog/linq-expand.aspx /// -#if NET35 - public sealed class ExpandableQuery : IQueryable, IOrderedQueryable, IOrderedQueryable +#if (NET35 || NET40 || NOEF) + public class ExpandableQuery : IQueryable, IOrderedQueryable, IOrderedQueryable +#elif EFCORE + public class ExpandableQuery : IQueryable, IOrderedQueryable, IOrderedQueryable, IAsyncEnumerable #else public class ExpandableQuery : IQueryable, IOrderedQueryable, IOrderedQueryable, IDbAsyncEnumerable #endif @@ -42,7 +50,16 @@ internal ExpandableQuery(IQueryable inner) /// IQueryable string presentation. public override string ToString() { return _inner.ToString(); } -#if !NET35 +#if !(NET35 || NET40 || NOEF) +#if EFCORE + IAsyncEnumerator IAsyncEnumerable.GetEnumerator() + { + if (_inner is IAsyncEnumerable) + return ((IAsyncEnumerable)_inner).GetEnumerator(); + + return (_inner as IAsyncEnumerableAccessor)?.AsyncEnumerable.GetEnumerator(); + } +#else /// Enumerator for async-await public IDbAsyncEnumerator GetAsyncEnumerator() { @@ -54,28 +71,40 @@ public IDbAsyncEnumerator GetAsyncEnumerator() IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator() { - return this.GetAsyncEnumerator(); + return GetAsyncEnumerator(); } +#endif #endif } -#if !NET35 +#if !(NET35 || NET40 || NOEF) internal class ExpandableQueryOfClass : ExpandableQuery - where T: class + where T : class { - public ExpandableQueryOfClass(IQueryable inner): base(inner) + public ExpandableQueryOfClass(IQueryable inner) : base(inner) { } +#if EFCORE + public IQueryable Include(Expression> navigationPropertyPath) + { + return ((IQueryable)InnerQuery.Include(navigationPropertyPath)).AsExpandable(); + } +#else public IQueryable Include(string path) { return InnerQuery.Include(path).AsExpandable(); } +#endif } +#endif - class ExpandableQueryProvider : IQueryProvider, IDbAsyncQueryProvider -#else class ExpandableQueryProvider : IQueryProvider +#if (NET35 || NET40 || NOEF) +#elif EFCORE + , IAsyncQueryProvider +#else + , IDbAsyncQueryProvider #endif { readonly ExpandableQuery _query; @@ -108,22 +137,35 @@ object IQueryProvider.Execute(Expression expression) return _query.InnerQuery.Provider.Execute(expression.Expand()); } -#if !NET35 - public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) - { - var asyncProvider = _query.InnerQuery.Provider as IDbAsyncQueryProvider; - if (asyncProvider != null) - return asyncProvider.ExecuteAsync(expression.Expand(), cancellationToken); - return Task.FromResult(_query.InnerQuery.Provider.Execute(expression.Expand())); - } - - public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) - { - var asyncProvider = _query.InnerQuery.Provider as IDbAsyncQueryProvider; - if (asyncProvider != null) - return asyncProvider.ExecuteAsync(expression.Expand(), cancellationToken); - return Task.FromResult(_query.InnerQuery.Provider.Execute(expression.Expand())); - } +#if !(NET35 || NET40 || NOEF) +#if EFCORE + public IAsyncEnumerable ExecuteAsync(Expression expression) + { + var asyncProvider = _query.InnerQuery.Provider as IAsyncQueryProvider; + return asyncProvider.ExecuteAsync(expression.Expand()); + } +#else + public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) + { + var asyncProvider = _query.InnerQuery.Provider as IDbAsyncQueryProvider; + if (asyncProvider != null) + return asyncProvider.ExecuteAsync(expression.Expand(), cancellationToken); + return Task.FromResult(_query.InnerQuery.Provider.Execute(expression.Expand())); + } +#endif + + public Task ExecuteAsync(Expression expression, CancellationToken cancellationToken) + { +#if EFCORE + var asyncProvider = _query.InnerQuery.Provider as IAsyncQueryProvider; +#else + var asyncProvider = _query.InnerQuery.Provider as IDbAsyncQueryProvider; +#endif + if (asyncProvider != null) + return asyncProvider.ExecuteAsync(expression.Expand(), cancellationToken); + + return Task.FromResult(_query.InnerQuery.Provider.Execute(expression.Expand())); + } #endif } -} +} \ No newline at end of file diff --git a/src/ExpressionExpander.cs b/src/ExpressionExpander.cs index 89f08f2..8db9023 100644 --- a/src/ExpressionExpander.cs +++ b/src/ExpressionExpander.cs @@ -1,169 +1,174 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Linq.Expressions; -using System.Collections.ObjectModel; -using System.Reflection; - -namespace LinqKit -{ - /// - /// Custom expresssion visitor for ExpandableQuery. This expands calls to Expression.Compile() and - /// collapses captured lambda references in subqueries which LINQ to SQL can't otherwise handle. - /// - class ExpressionExpander : ExpressionVisitor - { - // Replacement parameters - for when invoking a lambda expression. - readonly Dictionary _replaceVars = null; - - internal ExpressionExpander() { } - - private ExpressionExpander(Dictionary replaceVars) - { - _replaceVars = replaceVars; - } - - protected override Expression VisitParameter(ParameterExpression p) - { - return (_replaceVars != null) && (_replaceVars.ContainsKey(p)) ? _replaceVars[p] : base.VisitParameter(p); - } - - /// - /// Flatten calls to Invoke so that Entity Framework can understand it. Calls to Invoke are generated - /// by PredicateBuilder. - /// - protected override Expression VisitInvocation(InvocationExpression iv) - { - var target = iv.Expression; - if (target is MemberExpression) target = TransformExpr((MemberExpression)target); - if (target is ConstantExpression) target = ((ConstantExpression)target).Value as Expression; - - var lambda = (LambdaExpression)target; - - var replaceVars = _replaceVars == null ? - new Dictionary() - : new Dictionary(_replaceVars); - - try - { - for (int i = 0; i < lambda.Parameters.Count; i++) - replaceVars.Add(lambda.Parameters[i], this.Visit(iv.Arguments[i])); - } - catch (ArgumentException ex) - { - throw new InvalidOperationException("Invoke cannot be called recursively - try using a temporary variable.", ex); - } - - return new ExpressionExpander(replaceVars).Visit(lambda.Body); - } - - protected override Expression VisitMethodCall(MethodCallExpression m) - { - if (m.Method.Name == "Invoke" && m.Method.DeclaringType == typeof(Extensions)) - { - var target = m.Arguments[0]; - if (target is MemberExpression) target = TransformExpr((MemberExpression)target); - if (target is ConstantExpression) target = ((ConstantExpression)target).Value as Expression; - if (target is UnaryExpression) target = ((UnaryExpression)target).Operand as Expression; - +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; + +namespace LinqKit +{ + /// + /// Custom expresssion visitor for ExpandableQuery. This expands calls to Expression.Compile() and + /// collapses captured lambda references in subqueries which LINQ to SQL can't otherwise handle. + /// + class ExpressionExpander : ExpressionVisitor + { + // Replacement parameters - for when invoking a lambda expression. + readonly Dictionary _replaceVars = null; + + internal ExpressionExpander() { } + + private ExpressionExpander(Dictionary replaceVars) + { + _replaceVars = replaceVars; + } + + protected override Expression VisitParameter(ParameterExpression p) + { + return (_replaceVars != null) && (_replaceVars.ContainsKey(p)) ? _replaceVars[p] : base.VisitParameter(p); + } + + /// + /// Flatten calls to Invoke so that Entity Framework can understand it. Calls to Invoke are generated + /// by PredicateBuilder. + /// + protected override Expression VisitInvocation(InvocationExpression iv) + { + var target = iv.Expression; + if (target is MemberExpression) target = TransformExpr((MemberExpression)target); + if (target is ConstantExpression) target = ((ConstantExpression)target).Value as Expression; + + var lambda = (LambdaExpression)target; + + var replaceVars = _replaceVars == null ? + new Dictionary() + : new Dictionary(_replaceVars); + + try + { + for (int i = 0; i < lambda.Parameters.Count; i++) + replaceVars.Add(lambda.Parameters[i], this.Visit(iv.Arguments[i])); + } + catch (ArgumentException ex) + { + throw new InvalidOperationException("Invoke cannot be called recursively - try using a temporary variable.", ex); + } + + return new ExpressionExpander(replaceVars).Visit(lambda.Body); + } + + protected override Expression VisitMethodCall(MethodCallExpression m) + { + if (m.Method.Name == "Invoke" && m.Method.DeclaringType == typeof(Extensions)) + { + var target = m.Arguments[0]; + if (target is MemberExpression) target = TransformExpr((MemberExpression)target); + if (target is ConstantExpression) target = ((ConstantExpression)target).Value as Expression; + if (target is UnaryExpression) target = ((UnaryExpression)target).Operand as Expression; + var lambda = (LambdaExpression)target; - if (lambda != null) + if (lambda != null) { - var replaceVars = _replaceVars == null ? - new Dictionary() - : new Dictionary(_replaceVars); - - try - { - for (int i = 0; i < lambda.Parameters.Count; i++) - replaceVars.Add(lambda.Parameters[i], this.Visit(m.Arguments[i + 1])); - } - catch (ArgumentException ex) - { - throw new InvalidOperationException("Invoke cannot be called recursively - try using a temporary variable.", ex); - } - - return new ExpressionExpander(replaceVars).Visit(lambda.Body); - } - } - - // Expand calls to an expression's Compile() method: - if (m.Method.Name == "Compile" && m.Object is MemberExpression) - { - var me = (MemberExpression)m.Object; - var newExpr = TransformExpr(me); - if (newExpr != me) return newExpr; - } - - // Strip out any nested calls to AsExpandable(): - if (m.Method.Name == "AsExpandable" && m.Method.DeclaringType == typeof(Extensions)) - return m.Arguments[0]; - - return base.VisitMethodCall(m); - } - - protected override Expression VisitMemberAccess(MemberExpression m) - { - // Strip out any references to expressions captured by outer variables - LINQ to SQL can't handle these: - return m.Member.DeclaringType != null && m.Member.DeclaringType.Name.StartsWith("<>") ? - TransformExpr(m) - : base.VisitMemberAccess(m); - } - - Expression TransformExpr(MemberExpression input) - { - if (input == null) - return null; - - var field = input.Member as FieldInfo; - - if (field == null) - { - if ((_replaceVars != null) && (input.Expression is ParameterExpression) && (_replaceVars.ContainsKey(input.Expression as ParameterExpression))) - { - return base.VisitMemberAccess(input); - } - else - { - return input; - } - } - - // Collapse captured outer variables - if (input.Member.ReflectedType != null && (!input.Member.ReflectedType.IsNestedPrivate - || !input.Member.ReflectedType.Name.StartsWith("<>"))) // captured outer variable - { - return TryVisitExpressionFunc(input, field); - } - - var expression = input.Expression as ConstantExpression; - if (expression != null) - { - var obj = expression.Value; - if (obj == null) return input; - var t = obj.GetType(); - if (!t.IsNestedPrivate || !t.Name.StartsWith("<>")) return input; - var fi = (FieldInfo)input.Member; - var result = fi.GetValue(obj); - var exp = result as Expression; - if (exp != null) return Visit(exp); - } - - return TryVisitExpressionFunc(input, field); - - } - - private Expression TryVisitExpressionFunc(MemberExpression input, FieldInfo field) - { - var prope = input.Member as PropertyInfo; - if ((field.FieldType.IsSubclassOf(typeof(Expression))) || - (prope != null && prope.PropertyType.IsSubclassOf(typeof(Expression)))) - return Visit(Expression.Lambda>(input).Compile()()); - - return input; - } - } -} + var replaceVars = _replaceVars == null ? + new Dictionary() + : new Dictionary(_replaceVars); + + try + { + for (int i = 0; i < lambda.Parameters.Count; i++) + replaceVars.Add(lambda.Parameters[i], this.Visit(m.Arguments[i + 1])); + } + catch (ArgumentException ex) + { + throw new InvalidOperationException("Invoke cannot be called recursively - try using a temporary variable.", ex); + } + + return new ExpressionExpander(replaceVars).Visit(lambda.Body); + } + } + + // Expand calls to an expression's Compile() method: + if (m.Method.Name == "Compile" && m.Object is MemberExpression) + { + var me = (MemberExpression)m.Object; + var newExpr = TransformExpr(me); + if (newExpr != me) return newExpr; + } + + // Strip out any nested calls to AsExpandable(): + if (m.Method.Name == "AsExpandable" && m.Method.DeclaringType == typeof(Extensions)) + return m.Arguments[0]; + + return base.VisitMethodCall(m); + } + + protected override Expression VisitMemberAccess(MemberExpression m) + { + // Strip out any references to expressions captured by outer variables - LINQ to SQL can't handle these: + return m.Member.DeclaringType != null && m.Member.DeclaringType.Name.StartsWith("<>") ? + TransformExpr(m) + : base.VisitMemberAccess(m); + } + + Expression TransformExpr(MemberExpression input) + { + if (input == null) + return null; + + var field = input.Member as FieldInfo; + + if (field == null) + { + if ((_replaceVars != null) && (input.Expression is ParameterExpression) && (_replaceVars.ContainsKey(input.Expression as ParameterExpression))) + { + return base.VisitMemberAccess(input); + } + else + { + return input; + } + } +#if EFCORE || NETSTANDARD || WINDOWS_APP + //Collapse captured outer variables + if (input.Member.DeclaringType != null && (!input.Member.DeclaringType.GetTypeInfo().IsNestedPrivate + || !input.Member.DeclaringType.Name.StartsWith("<>"))) // captured outer variable + { + return TryVisitExpressionFunc(input, field); + } +#else + // Collapse captured outer variables + if (input.Member.ReflectedType != null && (!input.Member.ReflectedType.IsNestedPrivate + || !input.Member.ReflectedType.Name.StartsWith("<>"))) // captured outer variable + { + return TryVisitExpressionFunc(input, field); + } +#endif + + var expression = input.Expression as ConstantExpression; + if (expression != null) + { + var obj = expression.Value; + if (obj == null) return input; + var t = obj.GetType(); + if (!t.GetTypeInfo().IsNestedPrivate || !t.Name.StartsWith("<>")) return input; + var fi = (FieldInfo)input.Member; + var result = fi.GetValue(obj); + var exp = result as Expression; + if (exp != null) return Visit(exp); + } + + return TryVisitExpressionFunc(input, field); + + } + + private Expression TryVisitExpressionFunc(MemberExpression input, FieldInfo field) + { + var prope = input.Member as PropertyInfo; + if ((field.FieldType.GetTypeInfo().IsSubclassOf(typeof(Expression))) || + (prope != null && prope.PropertyType.GetTypeInfo().IsSubclassOf(typeof(Expression)))) + return Visit(Expression.Lambda>(input).Compile()()); + + return input; + } + } +} \ No newline at end of file diff --git a/src/Extensions.cs b/src/Extensions.cs index f7ff022..2b04311 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -1,9 +1,8 @@ using System; - using System.Collections.Generic; - using System.Linq.Expressions; using System.Linq; +using System.Reflection; namespace LinqKit { @@ -15,7 +14,7 @@ public static class Extensions public static IQueryable AsExpandable(this IQueryable query) { if (query is ExpandableQuery) return query; -#if !NET35 +#if !(NET35 || NET40 || NOEF) return ExpandableQueryFactory.Create(query); #else return new ExpandableQuery(query); @@ -66,7 +65,7 @@ public static TResult Invoke( return expr.Compile().Invoke(arg1, arg2, arg3, arg4); } -#if !NET35 +#if !(NET35 || NET40) /// LinqKit: Compile and invoke public static TResult Invoke( this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) @@ -75,100 +74,101 @@ public static TResult Invoke( } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15); + } /// LinqKit: Compile and invoke - public static TResult Invoke ( - this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, + public static TResult Invoke( + this Expression> expr, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15, T16 arg16) - { - return expr.Compile ().Invoke (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); - } + { + return expr.Compile().Invoke(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16); + } +#if !NOEF private static class ExpandableQueryFactory { public static readonly Func, ExpandableQuery> Create; static ExpandableQueryFactory() { - if (!typeof(T).IsClass) + if (!typeof(T).GetTypeInfo().IsClass) { Create = query => new ExpandableQuery(query); return; @@ -182,6 +182,7 @@ static ExpandableQueryFactory() Create = createExpr.Compile(); } } +#endif /// /// Correlates the elements of two sequences based on matching keys. The default equality comparer is used to compare keys. @@ -247,6 +248,7 @@ public static IQueryable LeftJoin(this I //IEnumerableInner.DefaultIfEmpty() Expression.Call(null, methodDefaultIfEmpty, parameterIEnumerableInner) }; + //new { Outer = Outer, IEnumerableInner = IEnumerableInner.DefaultIfEmpty()} var expressionGroupJoinResult = Expression.New(methodGroupJoinResultTypeConstructor, expressionGroupJoinResultArguments, typeGroupJoinResult.GetProperties()); //(Outer, IEnumerableInner) = > new { Outer = Outer, IEnumerableInner = IEnumerableInner.DefaultIfEmpty()} @@ -303,6 +305,5 @@ public static void ForEach(this IEnumerable source, Action action) } #endif - } } \ No newline at end of file diff --git a/src/IntrospectionExtensions.cs b/src/IntrospectionExtensions.cs new file mode 100644 index 0000000..ea4a214 --- /dev/null +++ b/src/IntrospectionExtensions.cs @@ -0,0 +1,22 @@ +namespace System.Reflection +{ + /// + /// https://github.com/castleproject/Core/blob/netcore/src/Castle.Core/Compatibility/IntrospectionExtensions.cs + /// + internal static class IntrospectionExtensions + { +#if NET35 || NET40 + // This allows us to use the new reflection API which separates Type and TypeInfo + // while still supporting .NET 3.5 and 4.0. This class matches the API of the same + // class in .NET 4.5+, and so is only needed on .NET Framework versions before that. + // + // Return the System.Type for now, we will probably need to create a TypeInfo class + // which inherits from Type like .NET 4.5+ and implement the additional methods and + // properties. + public static Type GetTypeInfo(this Type type) + { + return type; + } +#endif + } +} \ No newline at end of file diff --git a/src/Linq.cs b/src/Linq.cs index c8fa530..e481105 100644 --- a/src/Linq.cs +++ b/src/Linq.cs @@ -1,17 +1,14 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Linq.Expressions; namespace LinqKit { - /// - /// Another good idea by Tomas Petricek. - /// See http://tomasp.net/blog/dynamic-linq-queries.aspx for information on how it's used. - /// - public static class Linq - { + /// + /// Another good idea by Tomas Petricek. + /// See http://tomasp.net/blog/dynamic-linq-queries.aspx for information on how it's used. + /// + public static class Linq + { /// /// Returns the given anonymous method as a lambda expression /// @@ -47,10 +44,10 @@ public static Func Func(Func expr) /// /// Returns the given anonymous function as a Func delegate /// - public static Func Func (Func expr) - { - return expr; - } + public static Func Func(Func expr) + { + return expr; + } /// /// Returns the given anonymous function as a Func delegate @@ -59,5 +56,5 @@ public static Func Func(Func { return expr; } - } -} + } +} \ No newline at end of file diff --git a/src/LinqKit.Net35.csproj b/src/LinqKit.Net35.csproj index 4378c96..873eb51 100644 --- a/src/LinqKit.Net35.csproj +++ b/src/LinqKit.Net35.csproj @@ -5,7 +5,7 @@ AnyCPU 9.0.21022 2.0 - {AEC98F52-83F5-488D-99EF-8AFFE7C9F6E6} + {E6DA2678-2910-4EA4-B9F8-180E6BFD87B0} Library Properties LinqKit @@ -42,7 +42,7 @@ full false bin\Debug\net35\ - TRACE;DEBUG;NET35 + TRACE;DEBUG;CODE_ANALYSIS;NET35;EF prompt 4 false @@ -54,7 +54,7 @@ pdbonly true bin\Release\net35\ - TRACE;NET35 + TRACE;NET35;EF prompt 4 false @@ -75,6 +75,7 @@ + diff --git a/src/LinqKit.csproj b/src/LinqKit.csproj index f6dad56..9ea395d 100644 --- a/src/LinqKit.csproj +++ b/src/LinqKit.csproj @@ -42,7 +42,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;CODE_ANALYSIS;EF prompt 4 false @@ -54,7 +54,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;EF prompt 4 false @@ -64,11 +64,11 @@ - packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll True - packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True diff --git a/src/PredicateBuilder.cs b/src/PredicateBuilder.cs index 8706eb1..b051019 100644 --- a/src/PredicateBuilder.cs +++ b/src/PredicateBuilder.cs @@ -1,37 +1,34 @@ using System; using System.Linq; using System.Linq.Expressions; -using System.Collections.Generic; namespace LinqKit { - /// - /// See http://www.albahari.com/expressions for information and examples. - /// - public static class PredicateBuilder - { + /// + /// See http://www.albahari.com/expressions for information and examples. + /// + public static class PredicateBuilder + { /// Always true - public static Expression> True () { return f => true; } + public static Expression> True() { return f => true; } + /// Always false - public static Expression> False () { return f => false; } + public static Expression> False() { return f => false; } /// OR - public static Expression> Or (this Expression> expr1, - Expression> expr2) - { - var invokedExpr = Expression.Invoke (expr2.Expand(), expr1.Parameters.Cast ()); - return Expression.Lambda> - (Expression.OrElse (expr1.Body, invokedExpr), expr1.Parameters); - } + public static Expression> Or(this Expression> expr1, Expression> expr2) + { + var invokedExpr = Expression.Invoke(expr2.Expand(), expr1.Parameters.Cast()); + return Expression.Lambda> + (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); + } /// AND - public static Expression> And (this Expression> expr1, - Expression> expr2) - { - var invokedExpr = Expression.Invoke (expr2.Expand(), expr1.Parameters.Cast ()); - return Expression.Lambda> - (Expression.AndAlso (expr1.Body, invokedExpr), expr1.Parameters); - } - } - -} + public static Expression> And(this Expression> expr1, Expression> expr2) + { + var invokedExpr = Expression.Invoke(expr2.Expand(), expr1.Parameters.Cast()); + return Expression.Lambda> + (Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); + } + } +} \ No newline at end of file diff --git a/src/Tests/App.config b/src/Tests/App.config index c9eba71..2364782 100644 --- a/src/Tests/App.config +++ b/src/Tests/App.config @@ -2,7 +2,7 @@
- + @@ -13,4 +13,4 @@ - + diff --git a/src/Tests/DbAsyncTest.cs b/src/Tests/DbAsyncTest.cs index 3c111e2..6a715f7 100644 --- a/src/Tests/DbAsyncTest.cs +++ b/src/Tests/DbAsyncTest.cs @@ -1,53 +1,53 @@ -using System; -using System.Collections.Generic; -using System.Data.Entity; -using System.Linq; -using System.Linq.Expressions; -using System.Threading.Tasks; -using Xunit; - -namespace LinqKit.Tests -{ - public class DbAsyncTest - { - private readonly TestContext db = new TestContext(); - - public DbAsyncTest() - { - db.Entities.RemoveRange(db.Entities.ToList()); - db.Entities.AddRange(new[] - { - new Entity { Value = 123.45m }, - new Entity { Value = 67.89m }, - new Entity { Value = 3.14m } - }); - db.SaveChanges(); - } - - [Fact] - public async Task EnumerateShouldWorkAsync() - { - var task = db.Entities.AsExpandable().ToListAsync(); - var before = task.Status; - var result = await task; - var after = task.Status; - - Assert.Equal(TaskStatus.RanToCompletion, after); - Assert.Equal(3, result.Count); - Assert.NotEqual(TaskStatus.RanToCompletion, before); - } - - [Fact] - public async Task ExecuteShouldWorkAsync() - { - var task = db.Entities.AsExpandable().SumAsync(e => e.Value); - var before = task.Status; - var result = await task; - var after = task.Status; - - Assert.Equal(TaskStatus.RanToCompletion, after); - Assert.Equal(194.48m, result, 2); - Assert.NotEqual(TaskStatus.RanToCompletion, before); +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using Xunit; + +namespace LinqKit.Tests +{ + public class DbAsyncTest + { + private readonly TestContext db = new TestContext(); + + public DbAsyncTest() + { + db.Entities.RemoveRange(db.Entities.ToList()); + db.Entities.AddRange(new[] + { + new Entity { Value = 123.45m }, + new Entity { Value = 67.89m }, + new Entity { Value = 3.14m } + }); + db.SaveChanges(); + } + + [Fact] + public async Task EnumerateShouldWorkAsync() + { + var task = db.Entities.AsExpandable().ToListAsync(); + var before = task.Status; + var result = await task; + var after = task.Status; + + Assert.Equal(TaskStatus.RanToCompletion, after); + Assert.Equal(3, result.Count); + Assert.NotEqual(TaskStatus.RanToCompletion, before); + } + + [Fact] + public async Task ExecuteShouldWorkAsync() + { + var task = db.Entities.AsExpandable().SumAsync(e => e.Value); + var before = task.Status; + var result = await task; + var after = task.Status; + + Assert.Equal(TaskStatus.RanToCompletion, after); + Assert.Equal(194.48m, result, 2); + Assert.NotEqual(TaskStatus.RanToCompletion, before); } [Fact] @@ -72,17 +72,17 @@ where combined.Invoke(e) Assert.Equal(3.14m, res.First().Value); } - - public class TestContext : DbContext - { - public DbSet Entities { get; set; } - } - - public class Entity - { - public int Id { get; set; } - - public decimal Value { get; set; } - } - } -} + + public class TestContext : DbContext + { + public DbSet Entities { get; set; } + } + + public class Entity + { + public int Id { get; set; } + + public decimal Value { get; set; } + } + } +} diff --git a/src/Tests/LinqKit.Tests.csproj b/src/Tests/LinqKit.Tests.csproj index 5682fee..727de8a 100644 --- a/src/Tests/LinqKit.Tests.csproj +++ b/src/Tests/LinqKit.Tests.csproj @@ -1,5 +1,6 @@  + @@ -10,7 +11,7 @@ Properties LinqKit.Tests LinqKit.Tests - v4.5.1 + v4.5.2 512 @@ -35,11 +36,11 @@ - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + ..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll True - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + ..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True @@ -51,19 +52,19 @@ - ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll True - ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll + ..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll True - ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll + ..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll True - ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll + ..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll True @@ -91,7 +92,7 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +