-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from Avanade/feature/structV8
feat EntityFrameworkRepository extensions
- Loading branch information
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Liquid.Repository.EntityFramework/Extensions/ILiquidRepositoryExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Liquid.Core.Entities; | ||
using Liquid.Core.Interfaces; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq.Expressions; | ||
|
||
namespace Liquid.Repository.EntityFramework.Extensions | ||
{ | ||
/// <summary> | ||
/// Extension methods for <see cref="ILiquidRepository{TEntity, TIdentifier}"/>. | ||
/// </summary> | ||
[ExcludeFromCodeCoverage] | ||
public static class ILiquidRepositoryExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the list of entities that matches the where clause, | ||
/// including the related entities. | ||
/// </summary> | ||
/// <typeparam name="TEntity"></typeparam> | ||
/// <typeparam name="TIdentifier"></typeparam> | ||
/// <typeparam name="TContext"></typeparam> | ||
/// <param name="repository"></param> | ||
/// <param name="whereClause"> The where clause.</param> | ||
/// <param name="include"> The include clause.</param> | ||
/// <returns></returns> | ||
public static ILiquidRepository<TEntity, TIdentifier> WhereInclude<TEntity, TIdentifier, TContext>(this ILiquidRepository<TEntity, TIdentifier> repository | ||
, Expression<Func<TEntity, bool>> whereClause, Expression<Func<TEntity, object>> include = null) | ||
where TEntity : LiquidEntity<TIdentifier>, new() where TContext : DbContext | ||
{ | ||
var EfRepository = repository as EntityFrameworkRepository<TEntity, TIdentifier,TContext>; | ||
|
||
EfRepository.WhereInclude(whereClause, include); | ||
|
||
return repository; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the list of entities that matches the where clause, | ||
/// including the related entities. | ||
/// </summary> | ||
/// <typeparam name="TEntity"></typeparam> | ||
/// <typeparam name="TIdentifier"></typeparam> | ||
/// <typeparam name="TContext"></typeparam> | ||
/// <param name="repository"></param> | ||
/// <param name="whereClause">where clause.</param> | ||
/// <param name="includes">Entities to include.</param> | ||
/// <returns></returns> | ||
public static ILiquidRepository<TEntity, TIdentifier> WhereInclude<TEntity, TIdentifier, TContext>(this ILiquidRepository<TEntity, TIdentifier> repository | ||
, Expression<Func<TEntity, bool>> whereClause, string[] includes) | ||
where TEntity : LiquidEntity<TIdentifier>, new() where TContext : DbContext | ||
{ | ||
var EfRepository = repository as EntityFrameworkRepository<TEntity, TIdentifier, TContext>; | ||
|
||
EfRepository.WhereInclude(whereClause, includes); | ||
|
||
return repository; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/Liquid.Repository.EntityFramework.Tests/Entities/MockSubEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Liquid.Repository.EntityFramework.Tests.Entities | ||
{ | ||
public class MockSubEntity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters