SHARE
TWEET

Extension methods to clear Linq

TuukkaHaa Jan 5th, 2017 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
Top