asp.net core - Retrieving data for logged in user -


what best way retrieve data logged in user in api. can retrieve data users fine.

'applicationdbcontext':

public dbset<category> categories { get; set; } 

'applicationuser':

public icollection<category> categories { get; set; } 

my repository:

public class categoryrepository : icategoryrepository {     private applicationdbcontext _ctx;      public categoryrepository(applicationdbcontext ctx)     {         _ctx = ctx;     }      //to     public ienumerable<category> getall(string username)     {         return _ctx.users.first(...).categories.include(x => x.tasks);     }      public ienumerable<category> getallforfromallusers()     {         return _ctx.categories.include(x => x.tasks);     } } 

as have noticed above, can not use extension method 'include' on icollection. best way retrieve data specific user?

can try this?

var users = _ctx.users     .include(user => user.categories)         .theninclude(cat => cat.tasks)     .where(u => u.username == "xx")     .tolist(); 

from loading related data


Comments