Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

How to include multiple levels of related objects in EF Core?

$
0
0

I have these entities, ApplicationUser, UserProvider andPracticeProviders. the relationship between ApplicationUser andUserProvider is one-to-many and between the latter and PracticeProviders is one-to-many as well. I am trying to select a record inApplicationUser and its details from UserProvider and subsequently the data fromPracticeProviders.

publicclassApplicationUser:IdentityUser{publicstringFirstName{get;set;}publicstringLastName{get;set;}publicICollection<UserProvider>UserProviders{get;set;}publicApplicationUser(){UserProviders=newCollection<UserProvider>();}}publicclassUserProvider{publicstringUserId{get;set;}publicGuidProviderId{get;set;}publicPracticeProvidersProvider{get;set;}publicApplicationUserUser{get;set;}}publicclassPracticeProviders{publicPracticeProviders(){Id=Guid.NewGuid();}publicGuidId{get;set;}[Required]publicstringName{get;set;}publicstringAddress{get;set;}publicstringPhoneNumber{get;set;}publicICollection<UserProvider>UserProviders{get;set;}}

if I do,

publicasyncTask<ApplicationUser>GetUserDataByIdAsync(string userId){returnawaitthis.context.ApplicationUser.Include(user => user.UserProviders).Where(user => user.Id== userId).SingleOrDefaultAsync();}

I get only UserProviders data only, How can I get the details of each member in the collection list?

I tried ThenInclude() but I couldn't connect to deeper objects inPracticeProviders.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>