dotnet-data/README.md

75 lines
5.1 KiB
Markdown
Raw Permalink Normal View History

2019-11-12 19:27:13 -05:00
# Goal
2018-11-23 02:22:05 -05:00
The goal of this project is to help, fill the gap of supporting multiple ORM's in DynamicQuery, and possibly more projects in the future.
2018-12-07 00:35:03 -05:00
One of the most obvious reason is to be able to execute async/await operations on the context without, the executing library to be dependant on the ORM Framework such as (EF Core, EF6).
2018-11-23 02:22:05 -05:00
## Getting Started
> Install nuget package to your awesome project.
Full Version | NuGet | NuGet Install
------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------:
2018-11-23 02:23:07 -05:00
PoweredSoft.Data.Core | <a href="https://www.nuget.org/packages/PoweredSoft.Data.Core/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.Core.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.Core/)</a> | ```PM> Install-Package PoweredSoft.Data.Core```
2019-02-13 21:07:07 -05:00
PoweredSoft.Data | <a href="https://www.nuget.org/packages/PoweredSoft.Data/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data/)</a> | ```PM> Install-Package PoweredSoft.Data```
2019-11-27 21:19:12 -05:00
PoweredSoft.Data.EntityFramework | <a href="https://www.nuget.org/packages/PoweredSoft.Data.EntityFramework/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.EntityFramework.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.EntityFramework/)</a> | ```PM> Install-Package PoweredSoft.Data.EntityFramework```
2018-11-23 02:29:16 -05:00
PoweredSoft.Data.EntityFrameworkCore | <a href="https://www.nuget.org/packages/PoweredSoft.Data.EntityFrameworkCore/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.EntityFrameworkCore.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.EntityFrameworkCore/)</a> | ```PM> Install-Package PoweredSoft.Data.EntityFrameworkCore```
2019-02-13 21:07:07 -05:00
PoweredSoft.Data.MongoDB | <a href="https://www.nuget.org/packages/PoweredSoft.Data.MongoDB/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.MongoDB.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.MongoDB/)</a> | ```PM> Install-Package PoweredSoft.Data.MongoDB```
2021-08-11 17:43:45 -04:00
PoweredSoft.Data.InMemory | <a href="https://www.nuget.org/packages/PoweredSoft.Data.InMemory/" target="_blank">[![NuGet](https://img.shields.io/nuget/v/PoweredSoft.Data.InMemory.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/PoweredSoft.Data.InMemory/)</a> | ```PM> Install-Package PoweredSoft.Data.InMemory```
2018-11-23 02:29:16 -05:00
# In your application you may do the following
```csharp
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
2019-02-13 21:07:07 -05:00
// for mongo.
services.AddPoweredSoftMongoDBDataServices();
// for ef core
services.AddPoweredSoftEntityFrameworkCoreDataServices();
2021-08-11 17:43:45 -04:00
// for in memory
services.AddPoweredSoftInMemoryDataServices();
2018-11-23 02:29:16 -05:00
}
}
```
2019-11-12 19:27:13 -05:00
## AsyncQueryableService
2018-12-07 00:13:14 -05:00
2019-11-12 19:26:02 -05:00
Also as the same kind of goal, will slowly add support for a non dependant to orm/drivers async method.
2018-12-07 00:13:14 -05:00
```csharp
2019-02-13 21:07:07 -05:00
public interface IAsyncQueryableHandlerService
2018-12-07 00:13:14 -05:00
{
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken));
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken));
Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken));
Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken));
Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken));
2019-02-13 21:07:07 -05:00
Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken));
bool CanHandle<T>(IQueryable<T> queryable);
2018-12-07 00:13:14 -05:00
}
2019-02-13 21:07:07 -05:00
```
How to use
```csharp
public class SomeClass
{
private readonly IAsyncQueryableService asyncQueryableService;
2019-11-12 19:26:02 -05:00
public SomeClass(IAsyncQueryableService asyncQueryableService)
2019-02-13 21:07:07 -05:00
{
this.asyncQueryableService = asyncQueryableService;
}
public async Task<T> GetFirstAsync(IQueryable<T> query) {
return await this.asyncQueryableService.FirstOrDefaultAsync(query);
}
}
```