Advertisement
TuukkaHaa

Extension methods to clear Linq

Jan 5th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1.     var entities = await DbContext.SomeEntities
  2.         .NewerThan( query.UpdatedSince )
  3.         .ByIdAsync( query.Id );
  4.  
  5.     public static IQueryable<SomeEntity> Hankintapaatosehdotukset( this IQueryable<SomeEntity> source, DateTime updatedSince )
  6.     {
  7.         return source.Where( e => e.UpdatedSince >= updatedSince );
  8.     }
  9.  
  10.     public static async Task<SomeEntity> ByIdAsync( this IQueryable<SomeEntity> source, long id )
  11.     {
  12.         var entity = await source.SingleOrDefaultAsync( t => t.Id == id );
  13.         if ( entity == null ) { throw new NotFoundException( $"Entity not found with ID: {id}" ); }
  14.         return entity;
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement