The problem is that at the moment, you're selecting a sequence of sequences - one sequence of ShareholderUser items for each Shareholder. If you just want a list of ShareholderUser items, you need to flatten the results. That's most easily done using SelectMany
, which can actually replace your Select
call in this case.
List<ShareholderUser> list = dataContext.EJMCShareholderApprovals
.Where(e => e.EJMCRequestId == requestId)
.SelectMany(s => s.Shareholder.ShareholderUsers)
.Where(x => x.AccessMode == true)
.ToList();
Note how breaking the query over multiple lines makes it much simpler to read, too. Also, there's no point in initializing the list
variable to a new List<ShareholderUser>
if you're then immediately going to give it a different value. I've also removed the Include
call, as that was unnecessary - you're explicitly selecting Shareholder.ShareholderUsers
in the query, so you don't need to include it.