fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
572 stars 146 forks source link

Initial nested exists sub-query support. #603

Closed Thorium closed 5 years ago

Thorium commented 5 years ago
    let qry = 
        query {
            for o in dc.Main.Orders do
            where(query {
                    for od in dc.Main.OrderDetails do
                    exists(od.OrderId = o.OrderId)
                })
            select o.OrderId
        } |> Seq.toList

...produces:

SELECT [o].[OrderID] as 'OrderID' 
FROM main.Orders as [o] WHERE (
   (EXISTS (
        SELECT [od].[Discount] as 'Discount',[od].[OrderID] as 'OrderID',[od].[ProductID] as 'ProductID',[od].[Quantity] as 'Quantity',[od].[UnitPrice] as 'UnitPrice' 
        FROM main.OrderDetails as [od] 
        WHERE (([od].[OrderID] = [o].[OrderID]))
   ))
) 
Thorium commented 5 years ago

The whole baseAlias when "" is full-tablename is messy and should be replaced with normal alias, e.g. for o in orders should have alias of o and not Orders.

This is an issue when there are simple sub-queries that have no aliases but some aliasses can be inherited from the main-query. (free variables)

Thorium commented 5 years ago

The recent alias resolve fix did partly fix also the issues with this branch.