score:3
Accepted answer
You need to execute first and return an IEnumerable then with linq to Objects create a list
var events = (from c in context.Events.Include("EventPeople")
select new
{
ID = c.ID,
Title = c.Title,
Description = c.Description,
Date = c.Date,
People = (from ep in c.EventPeople
select new Domain.Entities.Person()
{
ID = ep.ID,
Name = ep.Name
})
}).ToList();
return events.Select(e => new Domain.Entities.Event()
{
ID = e.ID,
Title = e.Title,
Description = e.Description,
Date = e.Date,
People = e.People.ToList()
}).ToList();
Source: stackoverflow.com
Related Articles
- Initializing a List<T> using an EntityCollection that has a foreign key
- Need a LINQ code example to link two tables that have no foreign key
- Using Linq to get records that have specific foreign key
- How do I get the id of record in foreign key table using another column in that table in ASP.NET MVC?
- Convert string[] to int[] in one line of code using LINQ
- C# - code to order by a property using the property name as a string
- How do I find the text within a div in the source of a web page using C#
- Entity-framework code is slow when using Include() many times
- How are people unit testing code that uses Linq to SQL
- Finding first index of element that matches a condition using LINQ
- Using LINQ for an object that only has GetEnumerator()
- Using IDisposable object in method that returns IEnumerable<T>
- Using LINQ to Objects to find items in one collection that do not match another
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- Remove items from list that intersect on property using Linq
- select rows that do not have any foreign keys linked
- Check that all items of IEnumerable<T?> has the same value using LINQ
- Using LINQ's Zip with a closure that doesn't return a value
- linq deferred execution when using locks in methods that return IEnumerable
- Using LINQ to search a byte array for all subarrays that start/stop with certain byte
- Is there a good source that gives an overview of linq optimizations?
- Using LINQ to find all keys from one collection that are not in another?
- How to select values in list that are NOT IN a Table using EF Core?
- Using LINQ. With two different lists. How can I identify objects that do not match
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Get Value and Count of that value using LINQ or lambda expression
- Best way to handle redundant code that has repeated logic?
- Using LINQ to remove any value that is a duplicate
- Avoiding code repetition when using LINQ
- Group by in Linq with condition
- Default value and linq
- Least code to convert one object to anothe for both single object and List<object>?
- ?? operator didn't trigger System.DBNull type in DataTable DataRow
- How to avoid null values in LINQ command?
- Retrieving entities from a one to many relationship (Odata)
- Listing after implementing ranking skipping numbers
- How to retrieve friends from a database ASP, C#, Linq
- ArgumentException in linq query when using char.isDigit
- c# MVC Pass Group Data to View
- How to add where condition to list?
- C# LINQ to entities count items in nested table
- LINQ to XML: How to select the next element
- Show Image on repeater control
- Can I group-aggregate-calculate from another table directly in razor view?
- Linq List Contains Method
- linq to sql select specific cell
- Split 2D array to array with new rows
- Linq - operating on lists of lists
- Get top 3 most occuring numbers in a List