Skip to content

Commit f11ed9e

Browse files
committed
IncludePath and Strategy bugs #156 and #172
Some Warning removed Added project.json requested by VS2017
1 parent 379cd9f commit f11ed9e

23 files changed

Lines changed: 323 additions & 126 deletions

SharpRepository.EfRepository/EfRepositoryBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ protected override void AddItem(T entity)
3232
{
3333
if (typeof(TKey) == typeof(Guid) || typeof(TKey) == typeof(string))
3434
{
35-
TKey id;
36-
if (GetPrimaryKey(entity, out id) && Equals(id, default(TKey)))
35+
if (GetPrimaryKey(entity, out TKey id) && Equals(id, default(TKey)))
3736
{
3837
id = GeneratePrimaryKey();
3938
SetPrimaryKey(entity, id);
@@ -56,9 +55,8 @@ protected override void UpdateItem(T entity)
5655
{
5756
if (entry.State == EntityState.Detached)
5857
{
59-
TKey key;
6058

61-
if (GetPrimaryKey(entity, out key))
59+
if (GetPrimaryKey(entity, out TKey key))
6260
{
6361
// check to see if this item is already attached
6462
// if it is then we need to copy the values to the attached value instead of changing the State to modified since it will throw a duplicate key exception

SharpRepository.InMemoryRepository/SharpRepository.InMemoryRepository.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<Name>SharpRepository.Repository</Name>
5454
</ProjectReference>
5555
</ItemGroup>
56+
<ItemGroup>
57+
<None Include="project.json" />
58+
</ItemGroup>
5659
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5760
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
5861
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"frameworks": {
3+
"net452": {}
4+
},
5+
"runtimes": {
6+
"win10-x64": {},
7+
"win": {}
8+
}
9+
}

SharpRepository.Repository/CompoundKeyRepositoryBase.cs

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ public TResult Get<TResult>(Expression<Func<T, TResult>> selector, params object
191191

192192
public bool Exists(params object[] keys)
193193
{
194-
T entity;
195-
return TryGet(out entity, keys);
194+
return TryGet(out T entity, keys);
196195
}
197196

198197
public bool TryGet(out T entity, params object[] keys)
@@ -292,8 +291,7 @@ public TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TRes
292291

293292
public bool Exists(ISpecification<T> criteria)
294293
{
295-
T entity;
296-
return TryFind(criteria, out entity);
294+
return TryFind(criteria, out T entity);
297295
}
298296

299297
public bool TryFind(ISpecification<T> criteria, out T entity)
@@ -353,8 +351,7 @@ public TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Fun
353351

354352
public bool Exists(Expression<Func<T, bool>> predicate)
355353
{
356-
T entity;
357-
return TryFind(predicate, out entity);
354+
return TryFind(predicate, out T entity);
358355
}
359356

360357
public bool TryFind(Expression<Func<T, bool>> predicate, out T entity)
@@ -415,8 +412,7 @@ private void ProcessAdd(T entity, bool batchMode)
415412

416413
Save();
417414

418-
object[] keys;
419-
if (GetPrimaryKeys(entity, out keys))
415+
if (GetPrimaryKeys(entity, out object[] keys))
420416
_queryManager.OnItemAdded(keys, entity);
421417
}
422418

@@ -448,8 +444,7 @@ private void ProcessDelete(T entity, bool batchMode)
448444

449445
Save();
450446

451-
object[] keys;
452-
if (GetPrimaryKeys(entity, out keys))
447+
if (GetPrimaryKeys(entity, out object[] keys))
453448
_queryManager.OnItemDeleted(keys, entity);
454449
}
455450

@@ -498,8 +493,7 @@ private void ProcessUpdate(T entity, bool batchMode)
498493

499494
Save();
500495

501-
object[] keys;
502-
if (GetPrimaryKeys(entity, out keys))
496+
if (GetPrimaryKeys(entity, out object[] keys))
503497
_queryManager.OnItemUpdated(keys, entity);
504498
}
505499

@@ -777,8 +771,7 @@ public TResult Get<TResult>(TKey key, TKey2 key2, Expression<Func<T, TResult>> s
777771

778772
public bool Exists(TKey key, TKey2 key2)
779773
{
780-
T entity;
781-
return TryGet(key, key2, out entity);
774+
return TryGet(key, key2, out T entity);
782775
}
783776

784777
public bool TryGet(TKey key, TKey2 key2, out T entity)
@@ -893,8 +886,7 @@ public TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TRes
893886

894887
public bool Exists(ISpecification<T> criteria)
895888
{
896-
T entity;
897-
return TryFind(criteria, out entity);
889+
return TryFind(criteria, out T entity);
898890
}
899891

900892
public bool TryFind(ISpecification<T> criteria, out T entity)
@@ -954,8 +946,7 @@ public TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Fun
954946

955947
public bool Exists(Expression<Func<T, bool>> predicate)
956948
{
957-
T entity;
958-
return TryFind(predicate, out entity);
949+
return TryFind(predicate, out T entity);
959950
}
960951

961952
public bool TryFind(Expression<Func<T, bool>> predicate, out T entity)
@@ -1016,9 +1007,7 @@ private void ProcessAdd(T entity, bool batchMode)
10161007

10171008
Save();
10181009

1019-
TKey key;
1020-
TKey2 key2;
1021-
if (GetPrimaryKey(entity, out key, out key2))
1010+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2))
10221011
_queryManager.OnItemAdded(key, key2, entity);
10231012
}
10241013

@@ -1050,9 +1039,7 @@ private void ProcessDelete(T entity, bool batchMode)
10501039

10511040
Save();
10521041

1053-
TKey key;
1054-
TKey2 key2;
1055-
if (GetPrimaryKey(entity, out key, out key2))
1042+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2))
10561043
_queryManager.OnItemDeleted(key, key2, entity);
10571044
}
10581045

@@ -1101,9 +1088,7 @@ private void ProcessUpdate(T entity, bool batchMode)
11011088

11021089
Save();
11031090

1104-
TKey key;
1105-
TKey2 key2;
1106-
if (GetPrimaryKey(entity, out key, out key2))
1091+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2))
11071092
_queryManager.OnItemUpdated(key, key2, entity);
11081093
}
11091094

@@ -1381,8 +1366,7 @@ public TResult Get<TResult>(TKey key, TKey2 key2, TKey3 key3, Expression<Func<T,
13811366

13821367
public bool Exists(TKey key, TKey2 key2, TKey3 key3)
13831368
{
1384-
T entity;
1385-
return TryGet(key, key2, key3, out entity);
1369+
return TryGet(key, key2, key3, out T entity);
13861370
}
13871371

13881372
public bool TryGet(TKey key, TKey2 key2, TKey3 key3, out T entity)
@@ -1497,8 +1481,7 @@ public TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TRes
14971481

14981482
public bool Exists(ISpecification<T> criteria)
14991483
{
1500-
T entity;
1501-
return TryFind(criteria, out entity);
1484+
return TryFind(criteria, out T entity);
15021485
}
15031486

15041487
public bool TryFind(ISpecification<T> criteria, out T entity)
@@ -1558,8 +1541,7 @@ public TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Fun
15581541

15591542
public bool Exists(Expression<Func<T, bool>> predicate)
15601543
{
1561-
T entity;
1562-
return TryFind(predicate, out entity);
1544+
return TryFind(predicate, out T entity);
15631545
}
15641546

15651547
public bool TryFind(Expression<Func<T, bool>> predicate, out T entity)
@@ -1620,10 +1602,7 @@ private void ProcessAdd(T entity, bool batchMode)
16201602

16211603
Save();
16221604

1623-
TKey key;
1624-
TKey2 key2;
1625-
TKey3 key3;
1626-
if (GetPrimaryKey(entity, out key, out key2, out key3))
1605+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2, out TKey3 key3))
16271606
_queryManager.OnItemAdded(key, key2, key3, entity);
16281607
}
16291608

@@ -1655,10 +1634,7 @@ private void ProcessDelete(T entity, bool batchMode)
16551634

16561635
Save();
16571636

1658-
TKey key;
1659-
TKey2 key2;
1660-
TKey3 key3;
1661-
if (GetPrimaryKey(entity, out key, out key2, out key3))
1637+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2, out TKey3 key3))
16621638
_queryManager.OnItemDeleted(key, key2, key3, entity);
16631639
}
16641640

@@ -1707,10 +1683,7 @@ private void ProcessUpdate(T entity, bool batchMode)
17071683

17081684
Save();
17091685

1710-
TKey key;
1711-
TKey2 key2;
1712-
TKey3 key3;
1713-
if (GetPrimaryKey(entity, out key, out key2, out key3))
1686+
if (GetPrimaryKey(entity, out TKey key, out TKey2 key2, out TKey3 key3))
17141687
_queryManager.OnItemUpdated(key, key2, key3, entity);
17151688
}
17161689

SharpRepository.Repository/LinqCompoundKeyRepositoryBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override IQueryable<T> GetAllQuery(IFetchStrategy<T> fetchStrategy)
5252
protected override IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions, IFetchStrategy<T> fetchStrategy)
5353
{
5454
if (queryOptions == null)
55-
return GetAllQuery(null);
55+
return GetAllQuery(fetchStrategy);
5656

5757
var query = BaseQuery(fetchStrategy);
5858

@@ -141,7 +141,7 @@ protected override IQueryable<T> GetAllQuery(IFetchStrategy<T> fetchStrategy)
141141
protected override IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions, IFetchStrategy<T> fetchStrategy)
142142
{
143143
if (queryOptions == null)
144-
return GetAllQuery(null);
144+
return GetAllQuery(fetchStrategy);
145145

146146
var query = BaseQuery(fetchStrategy);
147147

@@ -230,9 +230,9 @@ protected override IQueryable<T> GetAllQuery(IFetchStrategy<T> fetchStrategy)
230230
protected override IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions, IFetchStrategy<T> fetchStrategy)
231231
{
232232
if (queryOptions == null)
233-
return GetAllQuery(null);
233+
return GetAllQuery(fetchStrategy);
234234

235-
var query = BaseQuery();
235+
var query = BaseQuery(fetchStrategy);
236236

237237
return queryOptions.Apply(query);
238238
}

SharpRepository.Repository/LinqRepositoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected override IQueryable<T> GetAllQuery(IQueryOptions<T> queryOptions, IFet
6161
if (queryOptions == null)
6262
return GetAllQuery(fetchStrategy);
6363

64-
var query = BaseQuery();
64+
var query = BaseQuery(fetchStrategy);
6565

6666
query = queryOptions.Apply(query);
6767

SharpRepository.Repository/Queries/QueryManager.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public QueryManager(ICachingStrategy<T, TKey> cachingStrategy)
3030

3131
public T ExecuteGet(Func<T> query, TKey key)
3232
{
33-
T result;
34-
35-
if (CacheEnabled && _cachingStrategy.TryGetResult(key, out result))
33+
if (CacheEnabled && _cachingStrategy.TryGetResult(key, out T result))
3634
{
3735
CacheUsed = true;
3836
return result;
@@ -48,8 +46,7 @@ public T ExecuteGet(Func<T> query, TKey key)
4846

4947
public IEnumerable<TResult> ExecuteGetAll<TResult>(Func<IEnumerable<TResult>> query, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions)
5048
{
51-
IEnumerable<TResult> result;
52-
if (CacheEnabled && _cachingStrategy.TryGetAllResult(queryOptions, selector, out result))
49+
if (CacheEnabled && _cachingStrategy.TryGetAllResult(queryOptions, selector, out IEnumerable<TResult> result))
5350
{
5451
CacheUsed = true;
5552
return result;
@@ -65,8 +62,7 @@ public IEnumerable<TResult> ExecuteGetAll<TResult>(Func<IEnumerable<TResult>> qu
6562

6663
public IEnumerable<TResult> ExecuteFindAll<TResult>(Func<IEnumerable<TResult>> query, ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions)
6764
{
68-
IEnumerable<TResult> result;
69-
if (CacheEnabled && _cachingStrategy.TryFindAllResult(criteria, queryOptions, selector, out result))
65+
if (CacheEnabled && _cachingStrategy.TryFindAllResult(criteria, queryOptions, selector, out IEnumerable<TResult> result))
7066
{
7167
CacheUsed = true;
7268
return result;
@@ -82,8 +78,7 @@ public IEnumerable<TResult> ExecuteFindAll<TResult>(Func<IEnumerable<TResult>> q
8278

8379
public TResult ExecuteFind<TResult>(Func<TResult> query, ISpecification<T> criteria, Expression<Func<T, TResult>> selector, IQueryOptions<T> queryOptions)
8480
{
85-
TResult result;
86-
if (CacheEnabled && _cachingStrategy.TryFindResult(criteria, queryOptions, selector, out result))
81+
if (CacheEnabled && _cachingStrategy.TryFindResult(criteria, queryOptions, selector, out TResult result))
8782
{
8883
CacheUsed = true;
8984
return result;

SharpRepository.Repository/RepositoryBase.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ public virtual IDictionary<TKey, T> GetManyAsDictionary(IEnumerable<TKey> keys)
444444

445445
public bool Exists(TKey key)
446446
{
447-
T entity;
448-
return TryGet(key, out entity);
447+
return TryGet(key, out T entity);
449448
}
450449

451450
public bool TryGet(TKey key, out T entity)
@@ -649,8 +648,7 @@ public TResult Find<TResult>(ISpecification<T> criteria, Expression<Func<T, TRes
649648

650649
public bool Exists(ISpecification<T> criteria)
651650
{
652-
T entity;
653-
return TryFind(criteria, out entity);
651+
return TryFind(criteria, out T entity);
654652
}
655653

656654
public bool TryFind(ISpecification<T> criteria, out T entity)
@@ -728,8 +726,7 @@ public TResult Find<TResult>(Expression<Func<T, bool>> predicate, Expression<Fun
728726

729727
public bool Exists(Expression<Func<T, bool>> predicate)
730728
{
731-
T entity;
732-
return TryFind(predicate, out entity);
729+
return TryFind(predicate, out T entity);
733730
}
734731

735732
public bool TryFind(Expression<Func<T, bool>> predicate, out T entity)
@@ -1345,10 +1342,9 @@ private void ProcessAdd(T entity, bool batchMode)
13451342

13461343
private void NotifyQueryManagerOfAddedEntity(T entity)
13471344
{
1348-
TKey key;
1349-
if (GetPrimaryKey(entity, out key))
1350-
QueryManager.OnItemAdded(key, entity);
1351-
}
1345+
if (GetPrimaryKey(entity, out TKey key))
1346+
QueryManager.OnItemAdded(key, entity);
1347+
}
13521348

13531349
public void Add(IEnumerable<T> entities)
13541350
{
@@ -1410,10 +1406,9 @@ private void ProcessDelete(T entity, bool batchMode)
14101406

14111407
private void NotifyQueryManagerOfDeletedEntity(T entity)
14121408
{
1413-
TKey key;
1414-
if (GetPrimaryKey(entity, out key))
1415-
QueryManager.OnItemDeleted(key, entity);
1416-
}
1409+
if (GetPrimaryKey(entity, out TKey key))
1410+
QueryManager.OnItemDeleted(key, entity);
1411+
}
14171412

14181413
public void Delete(IEnumerable<T> entities)
14191414
{
@@ -1517,10 +1512,9 @@ private void ProcessUpdate(T entity, bool batchMode)
15171512

15181513
private void NotifyQueryManagerOfUpdatedEntity(T entity)
15191514
{
1520-
TKey key;
1521-
if (GetPrimaryKey(entity, out key))
1522-
QueryManager.OnItemUpdated(key, entity);
1523-
}
1515+
if (GetPrimaryKey(entity, out TKey key))
1516+
QueryManager.OnItemUpdated(key, entity);
1517+
}
15241518

15251519
public void Update(IEnumerable<T> entities)
15261520
{
@@ -1584,8 +1578,7 @@ protected virtual void SetTraceInfo(string caller, IQueryable query, bool append
15841578

15851579
public TKey GetPrimaryKey(T entity)
15861580
{
1587-
TKey key;
1588-
if (GetPrimaryKey(entity, out key))
1581+
if (GetPrimaryKey(entity, out TKey key))
15891582
{
15901583
return key;
15911584
}

SharpRepository.Repository/SharpRepository.Repository.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
</ItemGroup>
178178
<ItemGroup>
179179
<None Include="packages.config" />
180+
<None Include="project.json" />
180181
</ItemGroup>
181182
<ItemGroup />
182183
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)