mardi 15 juin 2021

Shorter Parameter List with Defaults

Is their a way I can tidy this up

public Task<List<Categories>> GetAllCatgoriesViewModelAsyncByStoreId(Guid StoreId,Guid TennantId)
{
  return _context.Categories.Where(w => w.StoreId == StoreId && w.TennantId == TennantId).ToListAsync();
}

I know for where clauses I can do this.

modelBuilder.Entity<SalesOrder>().HasQueryFilter(q => q.isDeleted == false && q.isActive == true);           
modelBuilder.Entity<SalesOrderItem>().HasQueryFilter(q => q.isDeleted == false && q.isActive == true);

But it still means I have to do this every time (Guid StoreId,Guid TennantId) as below is their anyway to have a cleaner parameter List?

GetAllCatgoriesViewModelAsyncByStoreId(Guid StoreId,Guid TennantId)
 

//This version would still apply the above parameters but not having to create them each time both in the method signature and where clause

Something like .HasStoreTennantId

 public Task<List<Categories>> GetAllCatgoriesViewModelAsyncByStoreId()
 {
        return _context.Categories.HasStoreTennantId().ToListAsync();
 }




Aucun commentaire:

Enregistrer un commentaire