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
579 stars 146 forks source link

Left join entity is never null #697

Open JordanMarr opened 3 years ago

JordanMarr commented 3 years ago

Describe the bug I am trying to left join "sheets" entity but I can't get it to work properly.

The documentation says that leftOuterJoin is not supported, but I see examples on stackoverflow of people saying this works. For me it does not.

query {
        for e in ctx.Dbo.TimeEntries do
        join t in ctx.Dbo.ProjectTasks on (e.TaskId = t.Id)
        leftOuterJoin sheet in ctx.Dbo.DrawingLogSheets on (e.SheetId = Some sheet.Id) into sheetResults
        for s in sheetResults.DefaultIfEmpty() do
        where (e.Email = Some email && e.Date = dateOnly)
        select (toTimeEntry(e, t, s))
    }

This fails with an error.

I also tried this approach:

query {
        for e in ctx.Dbo.TimeEntries do
        join t in ctx.Dbo.ProjectTasks on (e.TaskId = t.Id)
        join s in (!!) ctx.Dbo.DrawingLogSheets on (e.SheetId = Some s.Id)
        where (e.Email = Some email && e.Date = dateOnly)
        select (toTimeEntry(e, t, s))
    }

This kind of works, but sheet is never null when it is missing; instead, it has all its values defaulted. For example, its ID field is a new guid (all zeros), and its string values are all empty string. I suppose I could check for defaulted guid, but this just feels like something is not right.

To Reproduce

Expected behavior In the first example (leftOuterJoin), I just want to verify whether this syntax is supposed to be supported or not. In the second example (!!), I would expect the sheet entity to be null when no sheet is joined, but instead it is instantiated with all default values.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

Thorium commented 3 years ago

This is kind of duplicate of #540