Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/Dime.Repositories.Sql/Dime.Repositories.Sql.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>2.0.3.0</VersionPrefix>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
<VersionPrefix>2.1.0.0</VersionPrefix>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Authors>Dime Software</Authors>
<Version>2.0.3.0</Version>
<Version>2.1.0.0-beta.2</Version>
<Authors>Dime Software</Authors>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>Dime.Repositories.Sql</AssemblyName>
Expand Down
8 changes: 4 additions & 4 deletions src/core/Dime.Repositories/Dime.Repositories.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.0.1.0</VersionPrefix>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
<FileVersion>2.0.1.0</FileVersion>
<VersionPrefix>2.1.0.0</VersionPrefix>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Authors>Dime Software</Authors>
<Version>2.0.1.0</Version>
<Version>2.1.0.0-beta.2</Version>
<TargetFrameworks>net8.0</TargetFrameworks>
<AssemblyName>Dime.Repositories</AssemblyName>
<PackageId>Dime.Repositories</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IDeleteRepository<TEntity> : IDisposable where TEntity : class

/// <summary>
/// Removes all records
/// </summary>
/// </summary>
/// <returns>Task</returns>
Task DeleteAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,14 @@ public partial interface IQueryRepositoryAsync<TEntity> : IDisposable where TEnt
/// <param name="ascending">Indicates whether the sorting is ascending (true) or descending (false)</param>
/// <param name="page">The page number which is multiplied by the pagesize to calculate the amount of items to skip</param>
/// <param name="pageSize">The size of the batch of items that must be retrieved</param>
/// <param name="includes">The optional list of related entities that should be eagerly loaded</param>
/// <returns>An instance of <typeparamref name="TResult"/> with the mapped data from the record that matched all filters.</returns>
Task<TResult> FindOneAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, object>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null,
params string[] includes)
int? pageSize = null)
where TResult : class;

/// <summary>
Expand Down Expand Up @@ -132,16 +130,14 @@ Task<TResult> FindOneAsync<TResult>(
/// <param name="orderBy">The sorting expression to execute against the data store</param>
/// <param name="page">The page number which is multiplied by the pagesize to calculate the amount of items to skip</param>
/// <param name="pageSize">The size of the batch of items that must be retrieved</param>
/// <param name="includes">The optional list of related entities that should be eagerly loaded</param>
/// <returns>An collection of <typeparamref name="TResult"/> with the mapped data from the records that matched all filters.</returns>
IEnumerable<TResult> FindAll<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, object>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null,
params string[] includes);
int? pageSize = null);

/// <summary>
/// Finds entities based on provided criteria.
Expand All @@ -160,16 +156,15 @@ IEnumerable<TResult> FindAll<TResult>(
/// <param name="orderBy">The sorting expression to execute against the data store</param>
/// <param name="page">The page number which is multiplied by the pagesize to calculate the amount of items to skip</param>
/// <param name="pageSize">The size of the batch of items that must be retrieved</param>
/// <param name="includes">The optional list of related entities that should be eagerly loaded</param>
/// <returns>An collection of <typeparamref name="TResult"/> with the mapped data from the records that matched all filters.</returns>
Task<IEnumerable<TResult>> FindAllAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TResult, bool>> selectWhere = null,
Expression<Func<TEntity, object>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null,
params string[] includes);
int? pageSize = null);

/// <summary>
/// Retrieves a collection of paged, sorted and filtered items in a flat list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
<VersionPrefix>2.0.3.0</VersionPrefix>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
<VersionPrefix>2.1.0.0</VersionPrefix>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand All @@ -24,7 +24,7 @@
<PackageId>Dime.Repositories.Sql.EntityFramework</PackageId>
<PackageTags>Entity Framework;Repository;SQL</PackageTags>
<PackageIconUrl>https://cdn.dime-software.com/dime-software/logo-shape.png</PackageIconUrl>
<Version>2.0.3.0</Version>
<Version>2.1.0.0-beta.2</Version>
<Description>Implementation of the repository pattern with Microsoft SQL using Entity Framework Core</Description>
<Copyright>Copyright © 2024</Copyright>
<PackageProjectUrl>https://github.com/dimesoftware/repository</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using LinqKit;
using Microsoft.EntityFrameworkCore;

namespace Dime.Repositories
{
public partial class EfRepository<TEntity, TContext>
{
public Task<TResult> FindOneAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = default,
int? page = default,
int? pageSize = default) where TResult : class
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsExpandable()
.AsQueryable()
.AsNoTracking()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select);

return Task.FromResult(query.FirstOrDefault());
}

public virtual Task<IEnumerable<TResult>> FindAllAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null)
=> FindAllAsync(where, select, null, orderBy, ascending, page, pageSize);

public virtual Task<IEnumerable<TResult>> FindAllAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TResult, bool>> selectWhere = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null)
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsNoTracking()
.AsExpandable()
.AsQueryable()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select, selectWhere);

return Task.FromResult(query.ToList() as IEnumerable<TResult>);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@ public virtual async Task<TEntity> FindOneAsync(Expression<Func<TEntity, bool>>
.WithFirst(where);
}

public Task<TResult> FindOneAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = default,
int? page = default,
int? pageSize = default,
params string[] includes) where TResult : class
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsExpandable()
.AsQueryable()
.AsNoTracking()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select)
.Include(Context, includes);

return Task.FromResult(query.FirstOrDefault());
}

public virtual async Task<IEnumerable<TEntity>> FindAllAsync(Expression<Func<TEntity, bool>> where, params string[] includes)
{
TContext ctx = Context;
Expand All @@ -90,30 +66,6 @@ public virtual async Task<IEnumerable<TEntity>> FindAllAsync(Expression<Func<TEn
return await Task.FromResult(query.ToList());
}

public virtual Task<IEnumerable<TResult>> FindAllAsync<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null,
params string[] includes)
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.Include(ctx, includes)
.AsNoTracking()
.AsExpandable()
.AsQueryable()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select);

return Task.FromResult(query.ToList() as IEnumerable<TResult>);
}

public virtual async Task<IEnumerable<TEntity>> FindAllAsync(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using LinqKit;
using Microsoft.EntityFrameworkCore;

namespace Dime.Repositories
{
public partial class EfRepository<TEntity, TContext>
{
public TResult FindOne<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = default,
int? page = default,
int? pageSize = default,
params string[] includes) where TResult : class
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsExpandable()
.AsQueryable()
.AsNoTracking()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select)
.Include(Context, includes);

return query.FirstOrDefault();
}

public virtual IEnumerable<TResult> FindAll<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null)
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsNoTracking()
.AsExpandable()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select);

return query.ToList();
}
}
}
47 changes: 0 additions & 47 deletions src/providers/EntityFramework/Repository/Sync/GetRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,6 @@ public virtual TEntity FindOne(Expression<Func<TEntity, bool>> where, params str
return query.FirstOrDefault();
}

public TResult FindOne<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = default,
int? page = default,
int? pageSize = default,
params string[] includes) where TResult : class
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.AsExpandable()
.AsQueryable()
.AsNoTracking()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select)
.Include(Context, includes);

return query.FirstOrDefault();
}

public IEnumerable<TEntity> FindAll(Expression<Func<TEntity, bool>> where)
{
using TContext ctx = Context;
Expand Down Expand Up @@ -130,29 +106,6 @@ public IEnumerable<TEntity> FindAll(Expression<Func<TEntity, bool>> where, int?
.Include(Context, includes);
}

public virtual IEnumerable<TResult> FindAll<TResult>(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, TResult>> select = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
bool? ascending = null,
int? page = null,
int? pageSize = null,
params string[] includes)
{
using TContext ctx = Context;
IQueryable<TResult> query = ctx.Set<TEntity>()
.Include(ctx, includes)
.AsNoTracking()
.AsExpandable()
.With(where)
.WithOrder(orderBy, ascending ?? true)
.With(page, pageSize, orderBy)
.With(pageSize)
.WithSelect(select);

return query.ToList();
}

public virtual IEnumerable<TEntity> FindAll(
Expression<Func<TEntity, bool>> where = null,
Expression<Func<TEntity, dynamic>> orderBy = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,5 @@ public Page<TEntity> FindAllPaged(

return new Page<TEntity>(query.ToList(), ctx.Count(where));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ internal static IQueryable<TResult> WithSelect<TSource, TResult>(this IQueryable
where TSource : class
=> selector == null ? default : source.Select(selector).AsQueryable();

internal static IQueryable<TResult> WithSelect<TSource, TResult>(this IQueryable<TSource> source,
Expression<Func<TSource, TResult>> selector,
Expression<Func<TResult, bool>> where)
where TSource : class
=> selector == null ? default : where == null ? source.Select(selector).AsQueryable() : source.Select(selector).Where(where).AsQueryable();

internal static IQueryable<TResult> WithSelect<TSource, TResult>(this IQueryable<TSource> source,
Func<TSource, TResult> selector)
where TSource : class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dime.Repositories.Sql.EntityFramework.Tests
{
[TestClass]
public partial class DeleteAsyncTests
{
{
[TestMethod]
public async Task DeleteAsync_ByEntity_ShouldRemoveOne()
{
Expand Down
Loading