EF63 support.

This commit is contained in:
David Lebee 2019-11-12 18:26:02 -06:00
parent a9d6546b67
commit 9b3d74f579
5 changed files with 76 additions and 16 deletions

View File

@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data", "Powered
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.Data.EntityFramework", "PoweredSoft.Data.EntityFramework\PoweredSoft.Data.EntityFramework.csproj", "{7BB489B2-58C0-4C49-A339-70E4CE750A40}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{34BED188-2B88-4CAD-8DD0-6FC70D156902}.Debug|Any CPU.Build.0 = Debug|Any CPU {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.ActiveCfg = Release|Any CPU {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.Build.0 = Release|Any CPU {34BED188-2B88-4CAD-8DD0-6FC70D156902}.Release|Any CPU.Build.0 = Release|Any CPU
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BB489B2-58C0-4C49-A339-70E4CE750A40}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using PoweredSoft.Data.Core;
namespace PoweredSoft.Data.EntityFramework
{
public class AsyncQueryableHandlerService : IAsyncQueryableHandlerService
{
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.FirstOrDefaultAsync(cancellationToken);
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.FirstOrDefaultAsync(predicate, cancellationToken);
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.ToListAsync(cancellationToken);
public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.CountAsync();
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.LongCountAsync();
public bool CanHandle<T>(IQueryable<T> queryable) => queryable.Provider is System.Data.Entity.Infrastructure.IDbAsyncQueryProvider;
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.AnyAsync(predicate, cancellationToken);
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
=> queryable.AnyAsync(cancellationToken);
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="6.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PoweredSoft.Data.Core\PoweredSoft.Data.Core.csproj" />
<ProjectReference Include="..\PoweredSoft.Data\PoweredSoft.Data.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,19 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using PoweredSoft.Data.Core;
using System;
using System.Collections.Generic;
using System.Text;
namespace PoweredSoft.Data.EntityFramework
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddPoweredSoftEntityFrameworkCoreDataServices(this IServiceCollection services)
{
services.AddPoweredSoftDataServices();
services.AddTransient<IAsyncQueryableHandlerService, AsyncQueryableHandlerService>();
return services;
}
}
}

View File

@ -32,23 +32,9 @@ public class Startup
} }
``` ```
> Then somewhere else.
```csharp
public class SomeClass
{
private readonly IDbContextFactory contextFactory;
public SomeClass(IDbContextFactoryProvider dbContextFactoryProvider)
{
contextFactory = dbContextFactoryProvider.GetContextFactory(typeof(YourFavoriteContext));
}
}
```
## AsyncQueryableFactory ## AsyncQueryableFactory
Also as the same kind of goal, will slowly add support for a non dependant to orm async method. Also as the same kind of goal, will slowly add support for a non dependant to orm/drivers async method.
```csharp ```csharp
public interface IAsyncQueryableHandlerService public interface IAsyncQueryableHandlerService
@ -70,7 +56,7 @@ How to use
public class SomeClass public class SomeClass
{ {
private readonly IAsyncQueryableService asyncQueryableService; private readonly IAsyncQueryableService asyncQueryableService;
public SomeClass(IDbContextFactoryProvider asyncQueryableService) public SomeClass(IAsyncQueryableService asyncQueryableService)
{ {
this.asyncQueryableService = asyncQueryableService; this.asyncQueryableService = asyncQueryableService;
} }