score:1
When I tried running it locally I got this exception
System.Exception: Grouping over multiple tables is not supported yet
I am not sure why you would be getting the less pretty version of that error. But if you pull the GroupBy out of the query, things seem to work fine.
query {
for student in db.Student do
join course in db.CourseSelection
on (student.StudentID = course.StudentID)
select (student.Name, course.Id)
}
|> Seq.countBy snd
|> Seq.iter (fun (student, classCount) -> printfn "Student %s has %i classes" student classCount)
score:0
I believe that the reason why your first query is not working is because of the groupBy student into group
.
I think what you actually want to write is groupBy student.StudentID into group
.
score:0
I found an answer from a similar question:
query {
for student in db.Student do
join course in db.CourseSelection
on (student.StudentID = course.StudentID)
let count = query {
for c in db.CourseSelection do
where (c.StudentID = student.StudentID)
select c
count
}
select (student.Name, count)
distinct
}
|> Seq.iter (fun (student, classCount) -> printfn "Student %s has %i classes" student classCount)
The underlying paradigm of these query expressions still eludes me.
EDIT:
I found that you can join implicitly without needing to use the join
operator
query {
for student in db.Student do
let count = query {
for course in student.CourseSelection do
count
}
select (student.Name, count)
}
|> Seq.iter (fun (name, count) -> printfn "%s has %i courses" name count)
Source: stackoverflow.com
Related Query
- F# Query Expression using join & groupBy in same query
- Construct a LINQ GroupBy query using expression trees
- How to write the same code using Lambda Expression
- The LINQ expression 'GroupByShaperExpression: could not be translated while using GROUPBY in LINQ query
- How to GroupBy using LINQ query in C# when the key is to be the same type as your type T when grouping List<T>
- Join Two Array based on Index and Index Value using Linq Query Expression Syntax
- Duplicate results with GroupBy using Linq Query Expression but not using Fluent Syntax
- How to retrieve last 5 records using LINQ method or query expression in C#
- How to query a nested list using a lambda expression
- String Join Using a Lambda Expression
- SQL Query to LINQ syntax using not exist and join
- Dynamic linq query expression tree for sql IN clause using Entity framework
- How to do a left outer join in Entity Framework without using the query syntax?
- Simple Linq query has duplicated join against same table?
- LINQ - using a query expression to calculate data time difference
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Outer join query using LINQ to Entities
- Writing Join Query Using Linq In VB.net
- Using a tuple or some other complex type in a Linq-to-Entities query expression
- How can I write the following code more elegantly using LINQ query syntax?
- Same LINQ query using joins but different conditions
- How can I code an outer join using LINQ and EF6?
- Entity Framework - writing query using lambda expression
- Generating a LINQ query using Expression Trees
- Lambda Expression LINQ Equivalent to SQL Exists Query on Same Table/Variable
- Query expressions over source type 'dynamic' or with a join sequence of type 'dynamic' are not allowed
- Why are parenthesis needed in F# using method chaining query expression where clause?
- Using query expression vs Seq modules?
- LINQ - sub query using OrderBy and GroupBy
More Query from same tag
- How to group a list so that a single record for a day on a DateTime field is retrived using Linq?
- Entity Framework Query to prefer a certain field value, if not select first or default
- Where does "i" get its value in this LINQ statement?
- SQL Select statement help: use row if value exists else use another row
- LINQ - Select Statement - The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type
- How to parse this xml in c#?
- Get value from XML through linq
- Execute expression on List
- Flatten a list which one of its properties is another list of object
- Sorting a nested list with linq
- Is AsList() better than ToList() with IDbConnection.Query() which returns IEnumerable?
- MVC LINQ Not recognised method
- Similar expression to "Coalesce" in Entity Framework
- Index of Child XElement
- Combining two streams of numbers using linq or rx
- How dynamically group by and compute aggregate sums/maximums data with LINQ in c#
- Linq select and add multiple values from the same object
- how to translate method call into lambda expression
- Can I rewrite this more elegantly using LINQ?
- A LINQ Challenge
- Getting single result from a query with anonymous types in Linq To Sql
- Null expression with dynamic LINQ
- Read first row of excel sheet using OpenXML and LINQ
- WPF: Get column name from selected row
- Linq get element from string list and a position of a char in this list
- Using LINQ lambda to replace characters from array in string
- LINQ to SQL performance, how to reduce contain parameters
- Why is this string only returned one time when using LINQ vs Regex?
- Find multiple files in the same directory
- Trying to set property in a LINQ GroupBy Select using a loop