score:6
Accepted answer
you want a groupjoin
rather than a join
. the difference is that rather than having all of the related items flattened into a list of pairs, it groups all of the joined items into a sequence:
var query = from p in context.person
join g in context.group
on p.personid equals g.personid into groups
select new
{
name = p.name,
age = p.age,
groupids = groups.select(g => g.groupid),
};
using query syntax the use of the into
keyword in conjunction with a join
will result in a groupjoin
instead of a join
.
score:2
i coded on so's editor. if i understand right you want person's groups. otherwise correct me please.
var p = from p in context.person
select new
{
name = p.name,
age = p.age,
groups = from g in context.group
where p.personid == g.personid
select g.groupid
};
Source: stackoverflow.com
Related Query
- How do I select multiple items from a database using LINQ
- How to select multiple values from a Dictionary using Linq as simple as possible
- How do I remove items from generic list, based on multiple conditions and using linq
- How to efficiently select certain items from two lists using LINQ
- Using LINQ and EF, how to remove values from database where not in list of items
- How to select all items from subcollections using LINQ
- How to get multiple column value from database into a list using LINQ query
- How to select multiple fields from a DataView and apply .Distinct() using LINQ
- How to populate a DropDownList from a SQL database using linq and only select Distinct Values
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to Select Multiple Fields from DataGridView using LINQ in C# WinForms
- how to select records from multiple table with max count value from one table using Linq in Asp.net MVC C#
- How to select from multiple tables using LINQ using a union query to return only one column?
- How to select values within a provided index range from a List using LINQ
- Linq - How to select items from a list that contains only items of another list?
- How do I select items from an array using an array of indices with Linq?
- How to reuse a linq expression for 'Where' when using multiple source tables
- How to consolidate results from multiple IEnumerable<T> using LINQ
- How to generate a unique list of items from another list using LINQ in C#
- how delete more than one record from database using Linq in asp.net mvc
- Select items from a List where the children contain the items from another List using LINQ
- linq how to select the parent from a collection where the parent contains child items in another collection
- How to select multiple values after using Max() in LINQ to Objects?
- How to select multiple columns from dataset into a string list with LinQ
- Using Linq to select multiple items per iteration?
- Optimized way to select items from a Collection excluding a list of certain member using Linq
- How to select multiple columns from datatable in linq group by?
- Using LINQ to select all from multiple tables
- Get Min and Max for items from database using Linq
- Select from multiple list using LINQ
More Query from same tag
- Use dictionary inside linq query
- How to format complex chained Linq statements for readibility?
- Querying XML attributes using LINQ
- c# LINQ to Entities does not recognize the method 'System.String ToString()' method
- Matching wrong Extension method
- how to find minimum difference object of collection in c# linq
- Get list of students whose first name is before their last name alphabetically
- Stored procedure or LINQ?
- Get different results with the same query in T-SQL and LINQ (EF Core)
- How to grouping list by a field and select into groups min of another field via linq?
- Search records with code pattern in column value c#
- How to get differences that caused Except to add an IEnumerable?
- LINQPAD - Read in a csv and store columns into lists
- Linq Query that returns IQueryable
- LINQ to SQL - Update to increment a non-primary-key field - thread-safe
- Unable to pass multiple values in the where clause of a LINQ query
- How to perform group by operation in dataTable using multiple columns in dynamically in c#?
- using Func<T, TResult> Delegate
- Matching XML elements to ListBox selected item - C#
- What is wrong with this dynamic dropdownlist?
- How can I build a linq query at runtime with multiple group by clauses with different types
- Get all objects in a list where a string parameter contains all strings in second list
- Split a string into a tuple using LINQ?
- Select values from elements with the particular class name
- Linq find min value of each object
- timezone in Where clause of linq query
- What is the best way to group groupings of groupings?
- How to find duplicate items based on multiple values using LINQ?
- Use anonymous type for LINQ based lists instead of var
- Parsing a string made from a LINQ statement to a method