Skip to content

Commit b11c1f1

Browse files
author
jtreuting
committed
Initial Join method for joing 2 repositories
This allows the ability to do query across 2 repositories that are related by a key without exposing the IQueryable stuff directly, which we probably don't want exposed too much since it's more of an internal thing
1 parent 428747c commit b11c1f1

26 files changed

+393
-145
lines changed

SharpRepository.InMemoryRepository/InMemoryRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using SharpRepository.Repository.Caching;
22

3-
namespace SharpRepository.Repository
3+
namespace SharpRepository.InMemoryRepository
44
{
55
public class InMemoryRepository<T, TKey> : InMemoryRepositoryBase<T, TKey> where T : class, new()
66
{

SharpRepository.InMemoryRepository/InMemoryRepositoryBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using SharpRepository.Repository;
45
using SharpRepository.Repository.Caching;
56
using SharpRepository.Repository.FetchStrategies;
67

7-
namespace SharpRepository.Repository
8+
namespace SharpRepository.InMemoryRepository
89
{
910
public abstract class InMemoryRepositoryBase<T, TKey> : LinqRepositoryBase<T, TKey> where T : class, new()
1011
{
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System;
2+
using System.Linq;
3+
using SharpRepository.Repository.FetchStrategies;
4+
5+
namespace SharpRepository.Repository
6+
{
7+
public class CompositeRepository<T, TKey> : LinqRepositoryBase<T, TKey>, IRepositoryQueryable<T, TKey> where T : class, new()
8+
{
9+
private readonly IQueryable<T> _baseQuery;
10+
11+
public CompositeRepository(IQueryable<T> baseQuery)
12+
{
13+
_baseQuery = baseQuery;
14+
}
15+
16+
17+
//public void Dispose()
18+
//{
19+
// _baseRepository.Dispose();
20+
//}
21+
22+
//public IQueryable<T> AsQueryable()
23+
//{
24+
// return _baseRepository.AsQueryable();
25+
//}
26+
27+
//public IRepositoryQueryable<TResult, TResultKey> Join<TOuterKey, TInner, TResult, TResultKey>(IRepositoryQueryable<TInner, TOuterKey> innerRepository, Expression<Func<T, TOuterKey>> outerKeySelector, Expression<Func<TInner, TOuterKey>> innerKeySelector, Expression<Func<T, TInner, TResult, TResultKey>> resultSelector) where TInner : class where TResult : class
28+
//{
29+
// return _baseRepository.Join(innerRepository, outerKeySelector, innerKeySelector, resultSelector);
30+
//}
31+
32+
//public T Get(TKey key)
33+
//{
34+
// return _baseRepository.Get(key);
35+
//}
36+
37+
//public TResult Get<TResult>(TKey key, Expression<Func<T, TResult>> selector)
38+
//{
39+
// return _baseRepository.Get(key, selector);
40+
//}
41+
42+
//public IEnumerable<T> GetAll()
43+
//{
44+
// return _baseRepository.GetAll();
45+
//}
46+
47+
//public IEnumerable<T> GetAll(IQueryOptions<T> queryOptions)
48+
//{
49+
// return _baseRepository.GetAll(queryOptions);
50+
//}
51+
52+
//public IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null)
53+
//{
54+
// return _baseRepository.GetAll(selector, queryOptions);
55+
//}
56+
57+
//public T Find(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null)
58+
//{
59+
// return _baseRepository.Find(predicate, queryOptions);
60+
//}
61+
62+
//public TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null)
63+
//{
64+
// return _baseRepository.Find(predicate, selector, queryOptions);
65+
//}
66+
67+
//public T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null)
68+
//{
69+
// return _baseRepository.Find(criteria, queryOptions);
70+
//}
71+
72+
//public TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null)
73+
//{
74+
// return _baseRepository.Find(criteria, selector, queryOptions);
75+
//}
76+
77+
//public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null)
78+
//{
79+
// return _baseRepository.FindAll(predicate, queryOptions);
80+
//}
81+
82+
//public IEnumerable<TResult> FindAll<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null)
83+
//{
84+
// return _baseRepository.FindAll(predicate, selector, queryOptions);
85+
//}
86+
87+
//public IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null)
88+
//{
89+
// return _baseRepository.FindAll(criteria, queryOptions);
90+
//}
91+
92+
//public IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null)
93+
//{
94+
// return _baseRepository.FindAll(criteria, selector, queryOptions);
95+
//}
96+
protected override void AddItem(T entity)
97+
{
98+
throw new NotImplementedException();
99+
}
100+
101+
protected override void DeleteItem(T entity)
102+
{
103+
throw new NotImplementedException();
104+
}
105+
106+
protected override void UpdateItem(T entity)
107+
{
108+
throw new NotImplementedException();
109+
}
110+
111+
protected override void SaveChanges()
112+
{
113+
throw new NotImplementedException();
114+
}
115+
116+
public override void Dispose()
117+
{
118+
119+
}
120+
121+
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
122+
{
123+
return _baseQuery;
124+
}
125+
}
126+
}

SharpRepository.Repository/IRepository.cs

Lines changed: 1 addition & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -13,125 +13,8 @@ namespace SharpRepository.Repository
1313
/// </summary>
1414
/// <typeparam name="T">The entity type that the repository acts on.</typeparam>
1515
/// <typeparam name="TKey">The type of the primary key.</typeparam>
16-
public interface IRepository<T, in TKey> : IDisposable where T : class
16+
public interface IRepository<T, in TKey> : IRepositoryQueryable<T, TKey> where T : class
1717
{
18-
/// <summary>
19-
/// Gives access to an IQueryable&lt;T&gt; for this repository. You can then use this to join with other IQueryable's for more complicated queries.
20-
/// </summary>
21-
/// <returns></returns>
22-
IQueryable<T> AsQueryable();
23-
24-
25-
/// <summary>
26-
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key.
27-
/// </summary>
28-
/// <param name="key">The primary key.</param>
29-
/// <returns>The entity that matches on the primary key</returns>
30-
T Get(TKey key);
31-
32-
/// <summary>
33-
/// Gets the specified entity of type <typeparamref name="T"/> from the repository by the primary key and maps it to the result of type <typeparamref name="TResult"/>.
34-
/// </summary>
35-
/// <typeparam name="TResult">The type of the result.</typeparam>
36-
/// <param name="key">The primary key.</param>
37-
/// <param name="selector">The mapping selector that returns the result type.</param>
38-
/// <returns>The mapped entity based on the selector that matches on the primary key.</returns>
39-
TResult Get<TResult>(TKey key, Expression<Func<T, TResult>> selector);
40-
41-
/// <summary>
42-
/// Gets all entities from the repository.
43-
/// </summary>
44-
/// <returns>All of the entities</returns>
45-
IEnumerable<T> GetAll();
46-
47-
/// <summary>
48-
/// Gets all entities from the repository and applies the query options (e.g. paging or sorting options)
49-
/// </summary>
50-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
51-
/// <returns></returns>
52-
IEnumerable<T> GetAll(IQueryOptions<T> queryOptions);
53-
54-
/// <summary>
55-
/// 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.
56-
/// </summary>
57-
/// <typeparam name="TResult">The type of the result.</typeparam>
58-
/// <param name="selector">The mapping selector that returns the result type.</param>
59-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
60-
/// <returns></returns>
61-
IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
62-
63-
/// <summary>
64-
/// Finds a single entity that matches the predicate supplied using FirstOrDefault with an optional query option, like sorting options.
65-
/// </summary>
66-
/// <param name="predicate">The predicate used to match entities against.</param>
67-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
68-
/// <returns></returns>
69-
T Find(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
70-
71-
/// <summary>
72-
/// 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.
73-
/// </summary>
74-
/// <typeparam name="TResult">The type of the result.</typeparam>
75-
/// <param name="predicate">The predicate used to match entities against.</param>
76-
/// <param name="selector">The mapping selector that returns the result type.</param>
77-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
78-
/// <returns></returns>
79-
TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
80-
81-
/// <summary>
82-
/// Finds a single entity that matches the specification criteria using FirstOrDefault with an optional query option, like sorting options.
83-
/// </summary>
84-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
85-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
86-
/// <returns></returns>
87-
T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
88-
89-
/// <summary>
90-
/// 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.
91-
/// </summary>
92-
/// <typeparam name="TResult">The type of the result.</typeparam>
93-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
94-
/// <param name="selector">The mapping selector that returns the result type.</param>
95-
/// <param name="queryOptions">The query options to use (usually sorting) since this uses FirstOrDefault.</param>
96-
/// <returns></returns>
97-
TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
98-
99-
/// <summary>
100-
/// Finds all entities that match the predicate with an optional query option applied (like paging or sorting).
101-
/// </summary>
102-
/// <param name="predicate">The predicate used to match entities against.</param>
103-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
104-
/// <returns></returns>
105-
IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null);
106-
107-
/// <summary>
108-
/// 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.
109-
/// </summary>
110-
/// <typeparam name="TResult">The type of the result.</typeparam>
111-
/// <param name="predicate">The predicate used to match entities against.</param>
112-
/// <param name="selector">The mapping selector that returns the result type.</param>
113-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
114-
/// <returns></returns>
115-
IEnumerable<TResult> FindAll<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
116-
117-
/// <summary>
118-
/// Finds all entities that match the specification criteria with an optional query option applied (like paging or sorting).
119-
/// </summary>
120-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
121-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
122-
/// <returns></returns>
123-
IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null);
124-
125-
/// <summary>
126-
/// 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.
127-
/// </summary>
128-
/// <typeparam name="TResult">The type of the result.</typeparam>
129-
/// <param name="criteria">The specification criteria that is used for matching entities against.</param>
130-
/// <param name="selector">The mapping selector that returns the result type.</param>
131-
/// <param name="queryOptions">The query options to apply like paging or sorting.</param>
132-
/// <returns></returns>
133-
IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions = null);
134-
13518
/// <summary>
13619
/// Adds the specified entity.
13720
/// </summary>

0 commit comments

Comments
 (0)