linq2sql left join with "multiselect"
Posted
by
just_azho
on Stack Overflow
See other posts from Stack Overflow
or by just_azho
Published on 2010-12-23T13:50:23Z
Indexed on
2010/12/23
13:54 UTC
Read the original article
Hit count: 170
sql-server-2005
|linq-to-sql
Hi, folks
I'm trying to achieve following by linq2sql, but not successful.
I've Member and Reference tables. DB is design in such a manner that Member can have multiple (>=0) References. What I want as a result of query is, list (rows) of members, where all references of the member are "collected" in one column.
What I had achieved is following query, but for this one there exist a row for each Reference.
var refs = (from m in db.Members
join
r in db.References on m.PID equals r.PID into g
from o in g.DefaultIfEmpty()
select new
{
member = m,
name = (o == null ? "" : o.NameSurname)
});
I feel I need to insert SelectMany somewher :)
Could you please give hints on achieving the goal?
© Stack Overflow or respective owner