Skip to content

Commit 88f4cdb

Browse files
author
Jeff Treuting
committed
Merge from develop into couchDb branch the changes for the IQueryable for the selector syntax to work as it should
1 parent f038e40 commit 88f4cdb

3 files changed

Lines changed: 21 additions & 25 deletions

File tree

SharpRepository.Repository/LinqRepositoryBase.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,28 @@ protected override T FindQuery(ISpecification<T> criteria, IQueryOptions<T> quer
4242
return criteria.SatisfyingEntityFrom(query);
4343
}
4444

45-
// TODO: change to IQueryable<T> so that we can use it from the calls with a selector like GetAll(x => x.Name), right now it is bringing back the entire object and then doing the Select using Linq to Objects
46-
protected override IEnumerable<T> GetAllQuery()
45+
protected override IQueryable<T> GetAllQuery()
4746
{
48-
// return BaseQuery(); // we should be doing this so that it can stay a query and not pull into memory for the GetAllQuery with the selector param to use as well
49-
return BaseQuery().ToList();
47+
return BaseQuery();
5048
}
5149

52-
protected override IEnumerable<T> GetAllQuery(IQueryOptions<T> queryOptions)
50+
protected override IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions)
5351
{
5452
if (queryOptions == null)
5553
return GetAllQuery();
5654

5755
var query = BaseQuery();
5856

59-
return queryOptions.Apply(query).ToList();
57+
return queryOptions.Apply(query);
6058
}
6159

62-
// TODO: change to IQueryable<T> so that we can use it from the calls with a selector like GetAll(x => x.Name), right now it is bringing back the entire object and then doing the Select using Linq to Objects
63-
protected override IEnumerable<T> FindAllQuery(ISpecification<T> criteria)
60+
protected override IQueryable<T> FindAllQuery(ISpecification<T> criteria)
6461
{
6562
var query = BaseQuery(criteria.FetchStrategy);
66-
return criteria.SatisfyingEntitiesFrom(query).ToList();
63+
return criteria.SatisfyingEntitiesFrom(query);
6764
}
6865

69-
protected override IEnumerable<T> FindAllQuery(ISpecification<T> criteria, IQueryOptions<T> queryOptions)
66+
protected override IQueryable<T> FindAllQuery(ISpecification<T> criteria, IQueryOptions<T> queryOptions)
7067
{
7168
if (queryOptions == null)
7269
return FindAllQuery(criteria);
@@ -75,7 +72,7 @@ protected override IEnumerable<T> FindAllQuery(ISpecification<T> criteria, IQuer
7572

7673
query = criteria.SatisfyingEntitiesFrom(query);
7774

78-
return queryOptions.Apply(query).ToList();
75+
return queryOptions.Apply(query);
7976
}
8077

8178
public override IEnumerator<T> GetEnumerator()

SharpRepository.Repository/RepositoryBase.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ protected RepositoryBase(ICachingStrategy<T, TKey> cachingStrategy = null)
5151

5252
public abstract IQueryable<T> AsQueryable();
5353

54-
// These are the actual implementation that the derived class needs to implement
55-
protected abstract IEnumerable<T> GetAllQuery();
56-
protected abstract IEnumerable<T> GetAllQuery(IQueryOptions<T> queryOptions);
54+
// These are the actual implementation that the derived class needs to implement
55+
protected abstract IQueryable<T> GetAllQuery();
56+
protected abstract IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions);
5757

5858
public IEnumerable<T> GetAll()
5959
{
@@ -72,10 +72,9 @@ public IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selecto
7272
{
7373
if (selector == null) throw new ArgumentNullException("selector");
7474

75-
// TODO: change to GetAllQuery which should be IQueryable<> so that the selector is done on the server side instead of inmemory with the resulting objects
76-
return GetAll(queryOptions)
77-
.AsQueryable()
78-
.Select(selector);
75+
return GetAllQuery(queryOptions)
76+
.Select(selector)
77+
.ToList();
7978
}
8079

8180
// These are the actual implementation that the derived class needs to implement
@@ -105,9 +104,9 @@ public TResult Get<TResult>(TKey key, Expression<Func<T, TResult>> selector)
105104
return results.AsQueryable().Select(selector).FirstOrDefault();
106105
}
107106

108-
// These are the actual implementation that the derived class needs to implement
109-
protected abstract IEnumerable<T> FindAllQuery(ISpecification<T> criteria);
110-
protected abstract IEnumerable<T> FindAllQuery(ISpecification<T> criteria, IQueryOptions<T> queryOptions);
107+
// These are the actual implementation that the derived class needs to implement
108+
protected abstract IQueryable<T> FindAllQuery(ISpecification<T> criteria);
109+
protected abstract IQueryable<T> FindAllQuery(ISpecification<T> criteria, IQueryOptions<T> queryOptions);
111110

112111
public IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null)
113112
{
@@ -124,7 +123,7 @@ public IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Express
124123
{
125124
if (criteria == null) throw new ArgumentNullException("criteria");
126125

127-
return FindAll(criteria, queryOptions).AsQueryable().Select(selector).ToList();
126+
return FindAllQuery(criteria, queryOptions).Select(selector).ToList();
128127
}
129128

130129
public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions<T> queryOptions = null)

SharpRepository.Tests.Integration/RepositoryGetAllTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public void GetAll_With_Anonymous_Selector_Should_Return_Every_Item(IRepository<
7575
repository.Add(contact);
7676
}
7777

78-
var result = repository.GetAll(c => new { c.Name, c.ContactTypeId});
78+
var results = repository.GetAll(c => new {c.Name, c.Title});
7979

80-
// changed from .Count() to this to actually get the results and not just the Count of the query which won't necessarily use the selector at all and might do it all server side
8180
var total = 0;
82-
foreach (var item in result)
81+
foreach (var result in results)
8382
{
83+
result.Name.ShouldStartWith("Test User");
8484
total++;
8585
}
8686
total.ShouldEqual(5);

0 commit comments

Comments
 (0)