EF63 support.
This commit is contained in:
parent
a9d6546b67
commit
9b3d74f579
6
Data.sln
6
Data.sln
@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data", "Powered
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PoweredSoft.Data.MongoDB", "PoweredSoft.Data.MongoDB\PoweredSoft.Data.MongoDB.csproj", "{34BED188-2B88-4CAD-8DD0-6FC70D156902}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.Data.EntityFramework", "PoweredSoft.Data.EntityFramework\PoweredSoft.Data.EntityFramework.csproj", "{7BB489B2-58C0-4C49-A339-70E4CE750A40}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
33
PoweredSoft.Data.EntityFramework/ASyncQueryableService.cs
Normal file
33
PoweredSoft.Data.EntityFramework/ASyncQueryableService.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -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>
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
18
README.md
18
README.md
@ -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
|
||||
|
||||
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
|
||||
public interface IAsyncQueryableHandlerService
|
||||
@ -70,7 +56,7 @@ How to use
|
||||
public class SomeClass
|
||||
{
|
||||
private readonly IAsyncQueryableService asyncQueryableService;
|
||||
public SomeClass(IDbContextFactoryProvider asyncQueryableService)
|
||||
public SomeClass(IAsyncQueryableService asyncQueryableService)
|
||||
{
|
||||
this.asyncQueryableService = asyncQueryableService;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user