I have the following function in my service layer csharp:
PS: A category can have List<Item>
public async Task<List<Category>> GetCategories(){ await using var db = await contextFactory.CreateDbContextAsync(); return await db.Categories .AsNoTracking() .OrderBy(c => c.Sort) .ToListAsync();}
public async Task<List<Category>> GetCategories(){ await using var db = await contextFactory.CreateDbContextAsync(); return await db.Categories .AsNoTracking() .OrderBy(c => c.Sort) .ToListAsync();}
Sometimes I need
GetCategories()
GetCategories()
to just be the
Category
Category
without any navigation properties included. But also sometimes I need
GetCategories()
GetCategories()
to also include the
Items
Items
navigation property...
I'm thinking of having two functions with two separate dtos (one has only the category, the other one has the category + the items).
But I was wondering if there's a better way to do this