Skip to content

Commit 64dd190

Browse files
committed
Fixed GetDeclaredMethods + Async (#24)
1 parent 6ba350d commit 64dd190

File tree

21 files changed

+183
-142
lines changed

21 files changed

+183
-142
lines changed

appveyor.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,25 @@ build_script:
2222
- appveyor-retry dotnet restore .\src\System.Linq.Dynamic.Core -v Minimal
2323
- appveyor-retry dotnet restore .\src\EntityFramework.DynamicLinq -v Minimal
2424
- appveyor-retry dotnet restore .\src\Microsoft.EntityFrameworkCore.DynamicLinq -v Minimal
25+
2526
- appveyor-retry dotnet restore .\test\System.Linq.Dynamic.Core.Tests -v Minimal
27+
- appveyor-retry dotnet restore .\test\EntityFramework.DynamicLinq.Tests -v Minimal
28+
29+
30+
- dotnet build .\src\System.Linq.Dynamic.Core\project.json -c %CONFIGURATION%
31+
- dotnet build .\src\EntityFramework.DynamicLinq\project.json -c %CONFIGURATION%
32+
- dotnet build .\src\Microsoft.EntityFrameworkCore.DynamicLinq\project.json -c %CONFIGURATION%
2633

27-
- dotnet build src\System.Linq.Dynamic.Core\project.json -c %CONFIGURATION%
28-
- dotnet build src\EntityFramework.DynamicLinq\project.json -c %CONFIGURATION%
29-
- dotnet build src\Microsoft.EntityFrameworkCore.DynamicLinq\project.json -c %CONFIGURATION%
30-
- dotnet build test\System.Linq.Dynamic.Core.Tests\project.json -c %CONFIGURATION%
34+
- dotnet build .\test\System.Linq.Dynamic.Core.Tests\project.json -c %CONFIGURATION%
35+
- dotnet build .\test\EntityFramework.DynamicLinq.Tests\project.json -c %CONFIGURATION%
3136

3237
- dotnet pack -c Release --no-build --version-suffix %LABEL% -o .\artifacts .\src\System.Linq.Dynamic.Core\project.json
3338
- dotnet pack -c Release --no-build --version-suffix %LABEL% -o .\artifacts .\src\EntityFramework.DynamicLinq\project.json
3439
- dotnet pack -c Release --no-build --version-suffix %LABEL% -o .\artifacts .\src\Microsoft.EntityFrameworkCore.DynamicLinq\project.json
3540

3641
test_script:
3742
- dotnet test -c %CONFIGURATION% --no-build .\test\System.Linq.Dynamic.Core.Tests
43+
- dotnet test -c %CONFIGURATION% --no-build .\test\EntityFramework.DynamicLinq.Tests
3844

3945
artifacts:
4046
- path: artifacts\**\*.*

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/App.config

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
</defaultConnectionFactory>
1515
<providers>
1616
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
17+
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
18+
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
1719
</providers>
1820
</entityFramework>
1921
<connectionStrings>
20-
<add name="DefaultConnection" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\EntityFrameworkTestDB.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
22+
<add name="DefaultConnection" connectionString="data source=.\ConsoleTestApp.net40.sqlite;foreign keys=true" providerName="System.Data.SQLite" />
2123
</connectionStrings>
24+
<system.data>
25+
<DbProviderFactories>
26+
<remove invariant="System.Data.SQLite.EF6" />
27+
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
28+
<remove invariant="System.Data.SQLite" />
29+
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
30+
</DbProviderFactories>
31+
</system.data>
2232
</configuration>

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/Program.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace System.Linq.Dynamic.Core.ConsoleTestApp.net40
1010
public class Program
1111
{
1212
static readonly Random Rnd = new Random(1);
13-
private static readonly BlogContext context = new BlogContext();
13+
private static readonly BlogContext context = new BlogContext("DefaultConnection");
1414

1515
public static void Main(string[] args)
1616
{
@@ -31,8 +31,8 @@ private static void DB()
3131
{
3232
try
3333
{
34-
context.Database.Delete();
35-
context.Database.CreateIfNotExists();
34+
//context.Database.Delete();
35+
//context.Database.CreateIfNotExists();
3636
PopulateTestData(10);
3737

3838
var expected = context.Blogs.Select(x => new { x.BlogId, x.Name, x.Posts }).ToArray();
@@ -44,7 +44,7 @@ private static void DB()
4444
}
4545
finally
4646
{
47-
context.Database.Delete();
47+
//context.Database.Delete();
4848
}
4949
}
5050

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/System.Linq.Dynamic.Core.ConsoleTestApp.net40.csproj

+23-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
<AssemblyName>System.Linq.Dynamic.Core.ConsoleTestApp.net40</AssemblyName>
1212
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
1416
</PropertyGroup>
1517
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1618
<PlatformTarget>AnyCPU</PlatformTarget>
1719
<DebugSymbols>true</DebugSymbols>
1820
<DebugType>full</DebugType>
1921
<Optimize>false</Optimize>
2022
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>TRACE;DEBUG;NET4</DefineConstants>
23+
<DefineConstants>TRACE;DEBUG;NET4;EF</DefineConstants>
2224
<ErrorReport>prompt</ErrorReport>
2325
<WarningLevel>4</WarningLevel>
2426
</PropertyGroup>
@@ -27,7 +29,7 @@
2729
<DebugType>pdbonly</DebugType>
2830
<Optimize>true</Optimize>
2931
<OutputPath>bin\Release\</OutputPath>
30-
<DefineConstants>TRACE;NET4</DefineConstants>
32+
<DefineConstants>TRACE;NET4;EF</DefineConstants>
3133
<ErrorReport>prompt</ErrorReport>
3234
<WarningLevel>4</WarningLevel>
3335
</PropertyGroup>
@@ -54,6 +56,18 @@
5456
<Reference Include="System" />
5557
<Reference Include="System.ComponentModel.DataAnnotations" />
5658
<Reference Include="System.Core" />
59+
<Reference Include="System.Data.SQLite, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
60+
<HintPath>..\..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net40\System.Data.SQLite.dll</HintPath>
61+
<Private>True</Private>
62+
</Reference>
63+
<Reference Include="System.Data.SQLite.EF6, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
64+
<HintPath>..\..\packages\System.Data.SQLite.EF6.1.0.101.0\lib\net40\System.Data.SQLite.EF6.dll</HintPath>
65+
<Private>True</Private>
66+
</Reference>
67+
<Reference Include="System.Data.SQLite.Linq, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
68+
<HintPath>..\..\packages\System.Data.SQLite.Linq.1.0.101.0\lib\net40\System.Data.SQLite.Linq.dll</HintPath>
69+
<Private>True</Private>
70+
</Reference>
5771
<Reference Include="System.Linq.Dynamic.Core">
5872
<HintPath>..\..\src\System.Linq.Dynamic.Core\bin\$(Configuration)\net40\System.Linq.Dynamic.Core.dll</HintPath>
5973
</Reference>
@@ -99,6 +113,13 @@
99113
<None Include="packages.config" />
100114
</ItemGroup>
101115
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
116+
<Import Project="..\..\packages\System.Data.SQLite.Core.1.0.101.0\build\net40\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.101.0\build\net40\System.Data.SQLite.Core.targets')" />
117+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
118+
<PropertyGroup>
119+
<ErrorText>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}.</ErrorText>
120+
</PropertyGroup>
121+
<Error Condition="!Exists('..\..\packages\System.Data.SQLite.Core.1.0.101.0\build\net40\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\System.Data.SQLite.Core.1.0.101.0\build\net40\System.Data.SQLite.Core.targets'))" />
122+
</Target>
102123
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
103124
Other similar extension points exist, see Microsoft.Common.targets.
104125
<Target Name="BeforeBuild">

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net40/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
<package id="EntityFramework" version="6.1.3" targetFramework="net40" />
44
<package id="JetBrains.Annotations" version="10.1.4" targetFramework="net40" />
55
<package id="SQLite.CodeFirst" version="1.2.1.13" targetFramework="net40" />
6+
<package id="System.Data.SQLite" version="1.0.101.0" targetFramework="net40" />
7+
<package id="System.Data.SQLite.Core" version="1.0.101.0" targetFramework="net40" />
8+
<package id="System.Data.SQLite.EF6" version="1.0.101.0" targetFramework="net40" />
9+
<package id="System.Data.SQLite.Linq" version="1.0.101.0" targetFramework="net40" />
610
</packages>

src-console/System.Linq.Dynamic.Core.ConsoleTestApp.net452/System.Linq.Dynamic.Core.ConsoleTestApp.net452.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<DebugType>full</DebugType>
3535
<Optimize>false</Optimize>
3636
<OutputPath>bin\Debug\</OutputPath>
37-
<DefineConstants>DEBUG;TRACE</DefineConstants>
37+
<DefineConstants>TRACE;DEBUG;EF</DefineConstants>
3838
<ErrorReport>prompt</ErrorReport>
3939
<WarningLevel>4</WarningLevel>
4040
</PropertyGroup>
@@ -43,7 +43,7 @@
4343
<DebugType>pdbonly</DebugType>
4444
<Optimize>true</Optimize>
4545
<OutputPath>bin\Release\</OutputPath>
46-
<DefineConstants>TRACE</DefineConstants>
46+
<DefineConstants>TRACE;EF</DefineConstants>
4747
<ErrorReport>prompt</ErrorReport>
4848
<WarningLevel>4</WarningLevel>
4949
</PropertyGroup>
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Data.Entity.Infrastructure;
1+
//using System.Data.Entity.Infrastructure;
22

3-
namespace EntityFramework.DynamicLinq
4-
{
5-
internal interface IAsyncQueryProvider : IDbAsyncQueryProvider
6-
{
7-
}
8-
}
3+
//namespace EntityFramework.DynamicLinq
4+
//{
5+
// internal interface IAsyncQueryProvider : IDbAsyncQueryProvider
6+
// {
7+
// }
8+
//}

src/Microsoft.EntityFrameworkCore.DynamicLinq/EFDynamicQueryableExtensions.cs

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if EFCORE
22
using Microsoft.EntityFrameworkCore.Query.Internal;
33
#else
4+
using System.Data.Entity.Infrastructure;
45
#endif
56
using System.Collections.Generic;
67
using System.Collections;
@@ -28,7 +29,7 @@ namespace EntityFramework.DynamicLinq
2829
/// </summary>
2930
public static class EntityFrameworkDynamicQueryableExtensions
3031
{
31-
#region AnyAsync
32+
#region AnyAsync
3233
private static readonly MethodInfo _any = GetMethod(nameof(Queryable.Any));
3334

3435
/// <summary>
@@ -89,9 +90,9 @@ public static class EntityFrameworkDynamicQueryableExtensions
8990

9091
return ExecuteAsync<bool>(_anyPredicate, source, Expression.Quote(lambda));
9192
}
92-
#endregion AnyAsync
93+
#endregion AnyAsync
9394

94-
#region FirstAsync
95+
#region FirstAsync
9596
private static readonly MethodInfo _first = GetMethod(nameof(Queryable.First));
9697

9798
/// <summary>
@@ -150,9 +151,9 @@ public static class EntityFrameworkDynamicQueryableExtensions
150151

151152
return ExecuteAsync<dynamic>(_firstPredicate, source, Expression.Quote(lambda), cancellationToken);
152153
}
153-
#endregion FirstAsync
154+
#endregion FirstAsync
154155

155-
#region FirstOrDefaultAsync
156+
#region FirstOrDefaultAsync
156157
private static readonly MethodInfo _firstOrDefault = GetMethod(nameof(Queryable.FirstOrDefault));
157158

158159
/// <summary>
@@ -217,9 +218,9 @@ public static class EntityFrameworkDynamicQueryableExtensions
217218
return ExecuteAsync<dynamic>(_firstOrDefaultPredicate, source, Expression.Quote(lambda), cancellationToken);
218219
}
219220

220-
#endregion FirstOrDefault
221+
#endregion FirstOrDefault
221222

222-
#region Private Helpers
223+
#region Private Helpers
223224
// Copied from https://github.com/aspnet/EntityFramework/blob/9186d0b78a3176587eeb0f557c331f635760fe92/src/Microsoft.EntityFrameworkCore/EntityFrameworkQueryableExtensions.cs
224225
//private static Task<dynamic> ExecuteAsync(MethodInfo operatorMethodInfo, IQueryable source, CancellationToken cancellationToken = default(CancellationToken))
225226
//{
@@ -242,7 +243,11 @@ public static class EntityFrameworkDynamicQueryableExtensions
242243

243244
private static Task<TResult> ExecuteAsync<TResult>(MethodInfo operatorMethodInfo, IQueryable source, CancellationToken cancellationToken = default(CancellationToken))
244245
{
246+
#if EFCORE
245247
var provider = source.Provider as IAsyncQueryProvider;
248+
#else
249+
var provider = source.Provider as IDbAsyncQueryProvider;
250+
#endif
246251

247252
if (provider != null)
248253
{
@@ -264,7 +269,11 @@ public static class EntityFrameworkDynamicQueryableExtensions
264269

265270
private static Task<TResult> ExecuteAsync<TResult>(MethodInfo operatorMethodInfo, IQueryable source, Expression expression, CancellationToken cancellationToken = default(CancellationToken))
266271
{
272+
#if EFCORE
267273
var provider = source.Provider as IAsyncQueryProvider;
274+
#else
275+
var provider = source.Provider as IDbAsyncQueryProvider;
276+
#endif
268277

269278
if (provider != null)
270279
{
@@ -289,6 +298,6 @@ private static MethodInfo GetMethod<TResult>(string name, int parameterCount = 0
289298

290299
private static MethodInfo GetMethod(string name, int parameterCount = 0, Func<MethodInfo, bool> predicate = null) =>
291300
typeof(Queryable).GetTypeInfo().GetDeclaredMethods(name).Single(mi => (mi.GetParameters().Length == parameterCount + 1) && ((predicate == null) || predicate(mi)));
292-
#endregion Private Helpers
301+
#endregion Private Helpers
293302
}
294303
}

src/System.Linq.Dynamic.Core/Res.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
internal static class Res
44
{
5-
public const string IQueryableProviderNotAsync = "The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IEntityQueryProvider can be used for Entity Framework asynchronous operations.";
5+
public const string IQueryableProviderNotAsync = "The provider for the source IQueryable doesn't implement IAsyncQueryProvider/IDbAsyncQueryProvider. Only providers that implement IAsyncQueryProvider/IDbAsyncQueryProvider can be used for Entity Framework asynchronous operations.";
66
public const string DuplicateIdentifier = "The identifier '{0}' was defined more than once";
77
public const string ExpressionTypeMismatch = "Expression of type '{0}' expected";
88
public const string ExpressionExpected = "Expression expected";

test/EntityFramework.DynamicLinq.Tests/App.config

-32
This file was deleted.

test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.xproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
55
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
66
</PropertyGroup>
7-
87
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
98
<PropertyGroup Label="Globals">
109
<ProjectGuid>3577bad5-cd9b-4b8f-b326-df11836e9e1f</ProjectGuid>
@@ -13,9 +12,11 @@
1312
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1413
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1514
</PropertyGroup>
16-
1715
<PropertyGroup>
1816
<SchemaVersion>2.0</SchemaVersion>
1917
</PropertyGroup>
18+
<ItemGroup>
19+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
20+
</ItemGroup>
2021
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21-
</Project>
22+
</Project>

test/EntityFramework.DynamicLinq.Tests/project.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"QueryInterceptor.Core": "1.0.3",
1010

1111
"EntityFramework": "6.1.3",
12-
"SQLite.CodeFirst": "1.2.0.12",
13-
12+
1413
"xunit": "2.1.0-rc2-build3178",
1514
"dotnet-test-xunit": "1.0.0-rc2-build10025"
1615
},
@@ -20,6 +19,7 @@
2019
"compile": {
2120
"include": [
2221
"../System.Linq.Dynamic.Core.Tests/EntitiesTests.cs",
22+
"../System.Linq.Dynamic.Core.Tests/EntitiesTests.Any.cs",
2323
"../System.Linq.Dynamic.Core.Tests/EntitiesTests.*Async.cs",
2424
"../System.Linq.Dynamic.Core.Tests/Entities/*.cs",
2525
"../System.Linq.Dynamic.Core.Tests/TestHelpers/*.cs",

test/System.Linq.Dynamic.Core.Tests/EntitiesOldTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void Entities_GroupBy_SingleKey_SingleResult()
251251
var expectedRow = expected[i];
252252

253253
//For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first
254-
var testRow = (IGrouping<DateTime, String>)test[i];
254+
var testRow = (IGrouping<DateTimeOffset, string>)test[i];
255255

256256
Assert.Equal(expectedRow.Key, testRow.Key);
257257
Assert.Equal(expectedRow.ToArray(), testRow.ToArray());
@@ -276,7 +276,7 @@ public void Entities_GroupBy_SingleKey_MultiResult()
276276
var expectedRow = expected[i];
277277

278278
//For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first
279-
var testRow = (IGrouping<DateTime, DynamicClass>)test[i];
279+
var testRow = (IGrouping<DateTimeOffset, DynamicClass>)test[i];
280280

281281
Assert.Equal(expectedRow.Key, testRow.Key);
282282
Assert.Equal(

0 commit comments

Comments
 (0)