I’m creating a linq query to get some data that will return a list of emails and some other info.
I’ve created the query so that i get the emails that i want, and the info. The thing is, it’s possible that the info will be the same for more than 1 email.
I want to know what’s the linq way to get a resultset that returns me something like
email1@domain.com,email2@domain.com | INFO
email3@domain.com | INFO2
email4@domain.com,email5@domain.com,email6@domain.com,email3@domain.com | INFO3
With the first property being a csv list of emails.
The query that I have right now is something like this :
from user in context.Users
join ufa in context.UFAccesses on user equals ufa.User
join f in context.F on ufa.Feed equals f
join fp in context.FP on f equals fp.F
select new { thisUfa = fp.F.UFAccess.Where(ufaSearch => ufaSearch.User == user && ufaSearch.F == f).FirstOrDefault(), user.Email, fp.Title, fp.Content };
EDIT : some extra info to help the answerer. maybe there’s a better way to do this. the main reason for the question is, since i’m getting this INFO several times (because it may correspond to more than 1 email), i’m getting innecessary data. later, i can do a loop in this resultset and for each info get a list of emails that correspond to it, but of course i’d like to get something more efficient and in linq if possible.
This one should solve your problem:
First we are grouping with
GroupBy(e => e.Info)and then selecting group key (Info) and joined emails: