Skip to content

Commit 620f9a0

Browse files
author
Jeff Treuting
committed
Post merge of join and develop cleanup/fixes
1 parent b31f438 commit 620f9a0

9 files changed

Lines changed: 365 additions & 473 deletions

File tree

Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Linq.Expressions;
5-
using SharpRepository.Repository.Queries;
6-
using SharpRepository.Repository.Specifications;
7-
8-
namespace SharpRepository.Repository
9-
{
10-
public interface IRepositoryQueryable<T> : IDisposable where T : class
11-
{
12-
IQueryable<T> AsQueryable(); // don't want this public, just for POC
13-
14-
IRepositoryQueryable<TResult> Join<TJoinKey, TInner, TResult>(IRepositoryQueryable<TInner> innerRepository, Expression<Func<T, TJoinKey>> outerKeySelector, Expression<Func<TInner, TJoinKey>> innerKeySelector, Expression<Func<T, TInner, TResult>> resultSelector)
15-
where TInner : class
16-
where TResult : class;
17-
18-
/// <summary>
19-
/// Gets all entities from the repository.
20-
/// </summary>
21-
/// <returns>All of the entities</returns>
22-
IEnumerable<T> GetAll();
23-
24-
/// <summary>
25-
/// Gets all entities from the repository and applies the query options (e.g. paging or sorting options)
26-
/// </summary>
27-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
28-
/// <returns></returns>
29-
IEnumerable<T> GetAll(IQueryOptions<T> queryOptions);
30-
31-
/// <summary>
32-
/// Gets all entities from the repository, applies the query options (e.g. paging or sorting options) and maps to a new types based on the selector.
33-
/// </summary>
34-
/// <typeparam name="TResult">The type of the result.</typeparam>
35-
/// <param name="selector">The mapping selector that returns the result type.</param>
36-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
37-
/// <returns></returns>
38-
IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
39-
40-
/// <summary>
41-
/// Finds a single entity that matches the predicate supplied using FirstOrDefault with an optional query option, like sorting options.
42-
/// </summary>
43-
/// <param name="predicate">The predicate used to match entities against.</param>
44-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
45-
/// <returns></returns>
46-
T Find(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
47-
48-
/// <summary>
49-
/// Finds a single entity that matches the predicate supplied using FirstOrDefault with an optional query option, like sorting options, and maps it to a new type based on the selector.
50-
/// </summary>
51-
/// <typeparam name="TResult">The type of the result.</typeparam>
52-
/// <param name="predicate">The predicate used to match entities against.</param>
53-
/// <param name="selector">The mapping selector that returns the result type.</param>
54-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
55-
/// <returns></returns>
56-
TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
57-
58-
/// <summary>
59-
/// Finds a single entity that matches the specification criteria using FirstOrDefault with an optional query option, like sorting options.
60-
/// </summary>
61-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
62-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
63-
/// <returns></returns>
64-
T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
65-
66-
/// <summary>
67-
/// Finds a single entity that matches the specification criteria using FirstOrDefault with an optional query option, like sorting options, and maps to a new type based on the selector.
68-
/// </summary>
69-
/// <typeparam name="TResult">The type of the result.</typeparam>
70-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
71-
/// <param name="selector">The mapping selector that returns the result type.</param>
72-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
73-
/// <returns></returns>
74-
TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
75-
76-
/// <summary>
77-
/// Finds all entities that match the predicate with an optional query option applied (like paging or sorting).
78-
/// </summary>
79-
/// <param name="predicate">The predicate used to match entities against.</param>
80-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
81-
/// <returns></returns>
82-
IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
83-
84-
/// <summary>
85-
/// Finds all entities that match the predicate with an optional query option applied (like paging or sorting), and maps to a new type based on the selector provided.
86-
/// </summary>
87-
/// <typeparam name="TResult">The type of the result.</typeparam>
88-
/// <param name="predicate">The predicate used to match entities against.</param>
89-
/// <param name="selector">The mapping selector that returns the result type.</param>
90-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
91-
/// <returns></returns>
92-
IEnumerable<TResult> FindAll<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
93-
94-
/// <summary>
95-
/// Finds all entities that match the specification criteria with an optional query option applied (like paging or sorting).
96-
/// </summary>
97-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
98-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
99-
/// <returns></returns>
100-
IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
101-
102-
/// <summary>
103-
/// Finds all entities that match the specification criteria with an optional query option applied (like paging or sorting), and maps to a new type based on the selector provided.
104-
/// </summary>
105-
/// <typeparam name="TResult">The type of the result.</typeparam>
106-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
107-
/// <param name="selector">The mapping selector that returns the result type.</param>
108-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
109-
/// <returns></returns>
110-
IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
111-
}
112-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
5+
using SharpRepository.Repository.Queries;
6+
using SharpRepository.Repository.Specifications;
7+
8+
namespace SharpRepository.Repository
9+
{
10+
public interface IRepositoryQueryable<T> : IEnumerable<T>, IDisposable where T : class
11+
{
12+
IQueryable<T> AsQueryable(); // don't want this public, just for POC
13+
14+
IRepositoryQueryable<TResult> Join<TJoinKey, TInner, TResult>(IRepositoryQueryable<TInner> innerRepository, Expression<Func<T, TJoinKey>> outerKeySelector, Expression<Func<TInner, TJoinKey>> innerKeySelector, Expression<Func<T, TInner, TResult>> resultSelector)
15+
where TInner : class
16+
where TResult : class;
17+
18+
/// <summary>
19+
/// Gets all entities from the repository.
20+
/// </summary>
21+
/// <returns>All of the entities</returns>
22+
IEnumerable<T> GetAll();
23+
24+
/// <summary>
25+
/// Gets all entities from the repository and applies the query options (e.g. paging or sorting options)
26+
/// </summary>
27+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
28+
/// <returns></returns>
29+
IEnumerable<T> GetAll(IQueryOptions<T> queryOptions);
30+
31+
/// <summary>
32+
/// Gets all entities from the repository, applies the query options (e.g. paging or sorting options) and maps to a new types based on the selector.
33+
/// </summary>
34+
/// <typeparam name="TResult">The type of the result.</typeparam>
35+
/// <param name="selector">The mapping selector that returns the result type.</param>
36+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
37+
/// <returns></returns>
38+
IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
39+
40+
/// <summary>
41+
/// Finds a single entity that matches the predicate supplied using FirstOrDefault with an optional query option, like sorting options.
42+
/// </summary>
43+
/// <param name="predicate">The predicate used to match entities against.</param>
44+
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
45+
/// <returns></returns>
46+
T Find(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
47+
48+
/// <summary>
49+
/// Finds a single entity that matches the predicate supplied using FirstOrDefault with an optional query option, like sorting options, and maps it to a new type based on the selector.
50+
/// </summary>
51+
/// <typeparam name="TResult">The type of the result.</typeparam>
52+
/// <param name="predicate">The predicate used to match entities against.</param>
53+
/// <param name="selector">The mapping selector that returns the result type.</param>
54+
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
55+
/// <returns></returns>
56+
TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
57+
58+
/// <summary>
59+
/// Finds a single entity that matches the specification criteria using FirstOrDefault with an optional query option, like sorting options.
60+
/// </summary>
61+
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
62+
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
63+
/// <returns></returns>
64+
T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
65+
66+
/// <summary>
67+
/// Finds a single entity that matches the specification criteria using FirstOrDefault with an optional query option, like sorting options, and maps to a new type based on the selector.
68+
/// </summary>
69+
/// <typeparam name="TResult">The type of the result.</typeparam>
70+
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
71+
/// <param name="selector">The mapping selector that returns the result type.</param>
72+
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
73+
/// <returns></returns>
74+
TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
75+
76+
/// <summary>
77+
/// Finds all entities that match the predicate with an optional query option applied (like paging or sorting).
78+
/// </summary>
79+
/// <param name="predicate">The predicate used to match entities against.</param>
80+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
81+
/// <returns></returns>
82+
IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
83+
84+
/// <summary>
85+
/// Finds all entities that match the predicate with an optional query option applied (like paging or sorting), and maps to a new type based on the selector provided.
86+
/// </summary>
87+
/// <typeparam name="TResult">The type of the result.</typeparam>
88+
/// <param name="predicate">The predicate used to match entities against.</param>
89+
/// <param name="selector">The mapping selector that returns the result type.</param>
90+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
91+
/// <returns></returns>
92+
IEnumerable<TResult> FindAll<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
93+
94+
/// <summary>
95+
/// Finds all entities that match the specification criteria with an optional query option applied (like paging or sorting).
96+
/// </summary>
97+
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
98+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
99+
/// <returns></returns>
100+
IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
101+
102+
/// <summary>
103+
/// Finds all entities that match the specification criteria with an optional query option applied (like paging or sorting), and maps to a new type based on the selector provided.
104+
/// </summary>
105+
/// <typeparam name="TResult">The type of the result.</typeparam>
106+
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
107+
/// <param name="selector">The mapping selector that returns the result type.</param>
108+
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
109+
/// <returns></returns>
110+
IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
111+
}
112+
}

SharpRepository.Repository/LinqRepositoryBase.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Linq.Expressions;
4+
using System.Linq.Expressions;
55
using SharpRepository.Repository.Caching;
66
using SharpRepository.Repository.FetchStrategies;
77
using SharpRepository.Repository.Queries;
88
using SharpRepository.Repository.Specifications;
99

1010
namespace SharpRepository.Repository
1111
{
12-
public abstract class LinqRepositoryBase<T, TKey> : RepositoryBase<T, TKey> where T : class
12+
public abstract class LinqRepositoryBase<T, TKey> : RepositoryBase<T, TKey> where T : class
1313
{
1414
protected LinqRepositoryBase(ICachingStrategy<T, TKey> cachingStrategy = null) : base(cachingStrategy)
1515
{
1616
}
17-
18-
public override IQueryable<T> AsQueryable()
17+
18+
public override IQueryable<T> AsQueryable()
1919
{
2020
return BaseQuery();
2121
}
@@ -74,11 +74,11 @@ protected override IEnumerable<T> FindAllQuery(ISpecification<T> criteria, IQuer
7474

7575
return queryOptions.Apply(query).ToList();
7676
}
77-
77+
7878
public override IEnumerator<T> GetEnumerator()
7979
{
8080
return BaseQuery().GetEnumerator();
81-
}
81+
}
8282

8383
public override IRepositoryQueryable<TResult> Join<TJoinKey, TInner, TResult>(IRepositoryQueryable<TInner> innerRepository, Expression<Func<T, TJoinKey>> outerKeySelector, Expression<Func<TInner, TJoinKey>> innerKeySelector, Expression<Func<T, TInner, TResult>> resultSelector)
8484
{
@@ -97,7 +97,7 @@ public override IRepositoryQueryable<TResult> Join<TJoinKey, TInner, TResult>(IR
9797
return new CompositeRepository<TResult>(outerQuery.Join(innerQuery, outerKeySelector, innerKeySelector, resultSelector));
9898
}
9999

100-
return new CompositeRepository<TResult>(outerQuery.Join(innerQuery, outerKeySelector, innerKeySelector, resultSelector));
100+
return new CompositeRepository<TResult>(outerQuery.Join(innerQuery, outerKeySelector, innerKeySelector, resultSelector));
101101
}
102102
}
103103
}

SharpRepository.Repository/RepositoryBase.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using System;
2+
using System.Collections;
23
using System.Reflection;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -358,6 +359,12 @@ private static PropertyInfo GetPropertyCaseInsensitive(IReflect type, string pro
358359
const BindingFlags bindingFlags = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
359360

360361
return type.GetProperty(propertyName, bindingFlags, null, propertyType, new Type[0], new ParameterModifier[0]);
361-
}
362+
}
363+
364+
public abstract IEnumerator<T> GetEnumerator();
365+
IEnumerator IEnumerable.GetEnumerator()
366+
{
367+
return GetEnumerator();
368+
}
362369
}
363370
}

0 commit comments

Comments
 (0)