score:2
Accepted answer
i am not sure if you are looking for something like this but it's a bit cleaner, it's not split in 2 statements and you might find it helpful. i couldn't use a dbcontext so i used lists to make sure the syntax is correct.
var res = shows.join(venues,
show => show.venueid,
venue => venue.venueid,
(show, venue) => new { show, venue })
.join(showdates,
val => val.show.showid,
showdate => showdate.showid,
(val, showdate) => new { val.show, val.venue, showdates = showdate })
.groupby(u => u.show.showid)
.select(grp => new
{
showid = grp.key,
name = grp.firstordefault()?.show.showname,
venue = grp.firstordefault()?.venue.venuename,
startdate = grp.max(g => g.showdates.datetime)
});
score:0
we need to now realation beetwen them one to one or one to many , but not too far from this answer.
var grouppedresult = shows.include(x=>x.veneu).include(x=>x.showdates)
.where(x=>x.veneu.any()&&x.showdates.any())
.groupby(x=>x.showid)
.select(x=>///anything you want);
or
from show in shows
join veneu in veneu on veneu.veneuid equals show.veneuid
join showdates in showdates on showdates.showid=show.showid
group show by show.id into grouppedshows
select new { ///what you want };
Source: stackoverflow.com
Related Query
- Converting SQL to LINQ with Multiple Tables and Group
- Group Joins with multiple tables converting SQL to Linq
- convert SQL query with multiple join on multiple tables using group by on multiple columns and with aggregate function into LINQ
- Multiple Tables Group and substract sum of columns using linq sql
- LINQ Group by on multiple tables with nested group by with join and aggregate
- Linq group by and sum with multiple tables
- Converting SQL Statement with Multiple Left Outer Joins and Various Clauses to LINQ
- converting a t-sql query to Linq to Sql with coalesce and multiple join
- SQL to LINQ with multiple joins and group by
- AP.NET webforms using LINQ to SQL datasource and databind with foreign keys across multiple tables
- LINQ Left Outer Join Multiple Tables with Group Count and Row Concatenation
- Converting an SQL with Left Join , Group and Sum to a Linq Query
- SQL to C# LINQ query with multiple group by inner queries and having clauses
- Convert SQL to Linq with multiple joins , SUM and group by
- LINQ version of sql query with multiple left joins, group by, and datetime conversion
- converting SQL join with group by and MAX to Linq
- LINQ version of sql query with multiple joins and group by
- Simple sql to Linq query with group by and aggregate functions
- LinQ query with multiple tables and extracting data
- Converting SQL containing top, count, group and order to LINQ (2 Entities)
- LINQ to SQL and Join two tables with OR clause
- SQL to LINQ with multiple join, count and left join
- LINQ to SQL join 3 tables and select multiple columns and also using Sum
- SQL to LINQ in C# (query with several tables and alias)
- C# Linq Join 2 tables on multiple columns and GROUP BY for count
- Not able to access fields with group by and multiple joins with linq
- LINQ to Sql Left Outer Join with Group By and Having Clause
- Pull data from multiple tables in one SQL query using LINQ and Entity Framework (Core)
- Entity Framework: How to perform left join with EF and LINQ among multiple tables
- Insert into multiple tables (one to one relationships) with Linq queries and SQLite
More Query from same tag
- How to get List of item using join in LINQ?
- How to check if string contains a string in string array
- Doubts about deferred execution
- ParallelEnumerable.Range vs Enumerable.Range.AsParallel?
- Linq ordering both parent and child related entities
- Join 2 tables with multiple references in LINQ
- Finding a control on a Winforms using LINQ?
- Linq groupby with count of particular column
- LINQ merging multiple lists
- Is LINQ's Any method efficient?
- ObjectQuery.select() method for linq to entities returns error
- How to get Control Value Form Control ID asp.net C#?
- Value Insert error in LINQ/C# for Column identity
- how to read XmlDocument by maximumn attribute to minimum attribute?
- LINQ OrderBy using condition AND Multiple columns
- get first three elements of jagged array
- linq xml extract text between tags
- Get position of specific element in ordered table
- How to use expression with null field with mongo
- C# - Troubles with IEnumerable.Where
- Implementing IComparable<T> Interface for a generic class to compare type T
- Get details record as property of master
- Reflection + Linq + DbSet
- Linq Includes Alternative
- Expose a repository as an IQueryable
- Can I cite a Compiled Query as the Data Source to a Compiled Query?
- Database connections (best practices)
- is there a better performance's way to get only few columns in ASP MVC without getting the whole table and filter it with LinQ?
- Beginner LINQ to XML inline XML error
- Using OrElse in a LINQ Statement