@@ -131,18 +131,19 @@ public IEnumerable<T> GetAll(IQueryOptions<T> queryOptions)
131131 try
132132 {
133133 var context = new RepositoryQueryMultipleContext < T , TKey > ( this , null , queryOptions ) ;
134- RunAspect ( attribute => attribute . OnGetAllExecuting ( context ) ) ;
134+ if ( ! RunAspect ( attribute => attribute . OnGetAllExecuting ( context ) ) )
135+ return context . Results ;
135136
136137 var results = QueryManager . ExecuteGetAll (
137- ( ) => GetAllQuery ( queryOptions ) . ToList ( ) ,
138+ ( ) => GetAllQuery ( context . QueryOptions ) . ToList ( ) ,
138139 null ,
139- queryOptions
140+ context . QueryOptions
140141 ) ;
141142
142143 context . Results = results ;
143144 RunAspect ( attribute => attribute . OnGetAllExecuted ( context ) ) ;
144145
145- return results ;
146+ return context . Results ;
146147 }
147148 catch ( Exception ex )
148149 {
@@ -158,18 +159,19 @@ public IEnumerable<TResult> GetAll<TResult>(Expression<Func<T, TResult>> selecto
158159 if ( selector == null ) throw new ArgumentNullException ( "selector" ) ;
159160
160161 var context = new RepositoryQueryMultipleContext < T , TKey , TResult > ( this , null , queryOptions , selector ) ;
161- RunAspect ( attribute => attribute . OnGetAllExecuting ( context ) ) ;
162+ if ( ! RunAspect ( attribute => attribute . OnGetAllExecuting ( context ) ) )
163+ return context . Results ;
162164
163165 var results = QueryManager . ExecuteGetAll (
164- ( ) => GetAllQuery ( queryOptions ) . Select ( selector ) . ToList ( ) ,
165- selector ,
166- queryOptions
166+ ( ) => GetAllQuery ( context . QueryOptions ) . Select ( context . Selector ) . ToList ( ) ,
167+ context . Selector ,
168+ context . QueryOptions
167169 ) ;
168170
169171 context . Results = results ;
170172 RunAspect ( attribute => attribute . OnGetAllExecuted ( context ) ) ;
171173
172- return results ;
174+ return context . Results ;
173175 }
174176 catch ( Exception ex )
175177 {
@@ -187,11 +189,11 @@ public abstract IRepositoryQueryable<TResult> Join<TJoinKey, TInner, TResult>(IR
187189
188190 public T Get ( TKey key )
189191 {
190-
191192 try
192193 {
193194 var context = new RepositoryGetContext < T , TKey > ( this , key ) ;
194- RunAspect ( attribute => attribute . OnGetExecuting ( context ) ) ;
195+ if ( ! RunAspect ( attribute => attribute . OnGetExecuting ( context ) ) )
196+ return context . Result ;
195197
196198 var result = QueryManager . ExecuteGet (
197199 ( ) => GetQuery ( key ) ,
@@ -212,21 +214,18 @@ public T Get(TKey key)
212214
213215 public TResult Get < TResult > ( TKey key , Expression < Func < T , TResult > > selector )
214216 {
215-
216217 try
217218 {
218219 if ( selector == null ) throw new ArgumentNullException ( "selector" ) ;
219220
220-
221221 var context = new RepositoryGetContext < T , TKey , TResult > ( this , key , selector ) ;
222- RunAspect ( attribute => attribute . OnGetExecuting ( context ) ) ;
223-
224-
222+ if ( ! RunAspect ( attribute => attribute . OnGetExecuting ( context ) ) )
223+ return context . Result ;
225224
226225 // get the full entity, possibly from cache
227226 var result = QueryManager . ExecuteGet (
228- ( ) => GetQuery ( key ) ,
229- key
227+ ( ) => GetQuery ( context . Id ) ,
228+ context . Id
230229 ) ;
231230
232231 // return the entity with the selector applied to it
@@ -237,7 +236,7 @@ public TResult Get<TResult>(TKey key, Expression<Func<T, TResult>> selector)
237236 context . Result = selectedResult ;
238237 RunAspect ( attribute => attribute . OnGetExecuted ( context ) ) ;
239238
240- return selectedResult ;
239+ return context . Result ;
241240 }
242241 catch ( Exception ex )
243242 {
@@ -294,11 +293,9 @@ public IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> query
294293
295294 try
296295 {
297- if ( criteria == null ) throw new ArgumentNullException ( "criteria" ) ;
298-
299-
300296 var context = new RepositoryQueryMultipleContext < T , TKey > ( this , criteria , queryOptions ) ;
301- RunAspect ( attribute => attribute . OnFindAllExecuting ( context ) ) ;
297+ if ( ! RunAspect ( attribute => attribute . OnFindAllExecuting ( context ) ) )
298+ return context . Results ;
302299
303300 var results = QueryManager . ExecuteFindAll (
304301 ( ) => FindAllQuery ( criteria , queryOptions ) . ToList ( ) ,
@@ -310,7 +307,7 @@ public IEnumerable<T> FindAll(ISpecification<T> criteria, IQueryOptions<T> query
310307 context . Results = results ;
311308 RunAspect ( attribute => attribute . OnFindAllExecuted ( context ) ) ;
312309
313- return results ;
310+ return context . Results ;
314311 }
315312 catch ( Exception ex )
316313 {
@@ -325,24 +322,23 @@ public IEnumerable<TResult> FindAll<TResult>(ISpecification<T> criteria, Express
325322
326323 try
327324 {
328- if ( criteria == null ) throw new ArgumentNullException ( "criteria" ) ;
329325 if ( selector == null ) throw new ArgumentNullException ( "selector" ) ;
330326
331-
332327 var context = new RepositoryQueryMultipleContext < T , TKey , TResult > ( this , criteria , queryOptions , selector ) ;
333- RunAspect ( attribute => attribute . OnFindAllExecuting ( context ) ) ;
328+ if ( ! RunAspect ( attribute => attribute . OnFindAllExecuting ( context ) ) )
329+ return context . Results ;
334330
335331 var results = QueryManager . ExecuteFindAll (
336- ( ) => FindAllQuery ( criteria , queryOptions ) . Select ( selector ) . ToList ( ) ,
337- criteria ,
338- selector ,
339- queryOptions
332+ ( ) => FindAllQuery ( context . Specification , context . QueryOptions ) . Select ( context . Selector ) . ToList ( ) ,
333+ context . Specification ,
334+ context . Selector ,
335+ context . QueryOptions
340336 ) ;
341337
342338 context . Results = results ;
343339 RunAspect ( attribute => attribute . OnFindAllExecuted ( context ) ) ;
344340
345- return results ;
341+ return context . Results ;
346342 }
347343 catch ( Exception ex )
348344 {
@@ -357,9 +353,6 @@ public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate, IQueryOptions
357353
358354 try
359355 {
360- if ( predicate == null ) throw new ArgumentNullException ( "predicate" ) ;
361-
362-
363356 return FindAll ( new Specification < T > ( predicate ) , queryOptions ) ;
364357 }
365358 catch ( Exception ex )
@@ -376,11 +369,6 @@ public IEnumerable<TResult> FindAll<TResult>(Expression<Func<T, bool>> predicate
376369
377370 try
378371 {
379- if ( predicate == null ) throw new ArgumentNullException ( "predicate" ) ;
380- if ( selector == null ) throw new ArgumentNullException ( "selector" ) ;
381-
382- if ( predicate == null ) return GetAll ( selector , queryOptions ) ;
383-
384372 return FindAll ( new Specification < T > ( predicate ) , selector , queryOptions ) ;
385373 }
386374 catch ( Exception ex )
@@ -400,21 +388,21 @@ public T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null)
400388 {
401389 if ( criteria == null ) throw new ArgumentNullException ( "criteria" ) ;
402390
403-
404391 var context = new RepositoryQuerySingleContext < T , TKey > ( this , criteria , queryOptions ) ;
405- RunAspect ( attribute => attribute . OnFindExecuting ( context ) ) ;
392+ if ( ! RunAspect ( attribute => attribute . OnFindExecuting ( context ) ) )
393+ return context . Result ;
406394
407395 var item = QueryManager . ExecuteFind (
408- ( ) => FindQuery ( criteria , queryOptions ) ,
409- criteria ,
396+ ( ) => FindQuery ( context . Specification , context . QueryOptions ) ,
397+ context . Specification ,
410398 null ,
411399 null
412400 ) ;
413401
414402 context . Result = item ;
415403 RunAspect ( attribute => attribute . OnFindExecuted ( context ) ) ;
416404
417- return item ;
405+ return context . Result ;
418406 }
419407 catch ( Exception ex )
420408 {
@@ -425,36 +413,35 @@ public T Find(ISpecification<T> criteria, IQueryOptions<T> queryOptions = null)
425413
426414 public TResult Find < TResult > ( ISpecification < T > criteria , Expression < Func < T , TResult > > selector , IQueryOptions < T > queryOptions = null )
427415 {
428-
429416 try
430417 {
431418 if ( criteria == null ) throw new ArgumentNullException ( "criteria" ) ;
432419 if ( selector == null ) throw new ArgumentNullException ( "selector" ) ;
433420
434-
435421 var context = new RepositoryQuerySingleContext < T , TKey , TResult > ( this , criteria , queryOptions , selector ) ;
436- RunAspect ( attribute => attribute . OnFindExecuting ( context ) ) ;
422+ if ( ! RunAspect ( attribute => attribute . OnFindExecuting ( context ) ) )
423+ return context . Result ;
437424
438425 var item = QueryManager . ExecuteFind (
439426 ( ) =>
440427 {
441- var result = FindQuery ( criteria , queryOptions ) ;
428+ var result = FindQuery ( context . Specification , context . QueryOptions ) ;
442429 if ( result == null )
443430 return default ( TResult ) ;
444431
445432 var results = new [ ] { result } ;
446- return results . AsQueryable ( ) . Select ( selector ) . First ( ) ;
433+ return results . AsQueryable ( ) . Select ( context . Selector ) . First ( ) ;
447434 } ,
448435
449- criteria ,
450- selector ,
436+ context . Specification ,
437+ context . Selector ,
451438 null
452439 ) ;
453440
454441 context . Result = item ;
455442 RunAspect ( attribute => attribute . OnFindExecuted ( context ) ) ;
456443
457- return item ;
444+ return context . Result ;
458445 }
459446 catch ( Exception ex )
460447 {
0 commit comments