Answer the question
In order to leave comments, you need to log in
How to load a collection of elements through a many-to-many relationship in Entity Framework?
Good day.
Now I am writing a program using Entity Framework 6 and I am binding data from the context to the DataGridView.
There are 3 entities: Wallet, WalletM2M, Account. Wallet and Account are related to WalletM2M by a many-to-many relationship. You need to get a list of Wallet records, knowing only the data about a particular Account record.
I do it like this:
var l = context.Wallet.Include(w => w.WalletM2M).Select(w => w.WalletM2M
.Where(wM2M => wM2M.AccountId == CurrentUser.AccountId && wM2M.IsAdmin == true)).ToList();
Answer the question
In order to leave comments, you need to log in
If you want to get the wallet to the current userid, then just filter
context.Wallet.Include(w => w.WalletM2M)
.Where(w => w.WalletM2M.AccountId == CurrentUser.AccountId && w.WalletM2M.IsAdmin == true).ToList();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question