Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single case union support #98

Merged
merged 4 commits into from
Jun 14, 2021
Merged

Single case union support #98

merged 4 commits into from
Jun 14, 2021

Conversation

lucasteles
Copy link
Contributor

Proposed Changes

Single case union types (aka Simple types)

It's common to use single case discriminated unions to meaningfully represent data values.
EF does not know anything about this kind of type. This PR enables migration and mapping of single case discriminated unions

Example:

type PostitiveInteger = PositiveInteger of int

[<CLIMutable>]
type Blog = {
    [<Key>]
    Id : Guid
    Title : string
    Votes: PositiveInteger
}

type MyContext () =
    inherit DbContext()

    [<DefaultValue>]
    val mutable private _blogs : DbSet<Blog>
    member this.Blogs with get() = this._blogs and set v = this._blogs <- v

    override _.OnModelCreating builder =
        builder.RegisterSingleUnionCases()


let sample ctx = 
               query {
                   for blog in ctx.Blogs do
                   where (blog.Votes = PositiveInteger 10)
                   select blog
                   headOrDefault
               }

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Build and tests pass locally
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

@simon-reynolds
Copy link
Collaborator

Ties into #66

@simon-reynolds
Copy link
Collaborator

Hi @lucasteles
I like this change a lot! Can you resolve the conflict please and I'll approve and merge

@lucasteles
Copy link
Contributor Author

Resolved!

@simon-reynolds simon-reynolds merged commit 70aa99c into efcore:master Jun 14, 2021
simon-reynolds added a commit that referenced this pull request Jun 16, 2021
## [5.0.3-beta004] - 2021-06-16

### Added
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98

- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
[Unreleased]: v5.0.3-beta002...HEAD
[5.0.3-beta002]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-beta002
[5.0.3-beta001]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-beta001
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
[Unreleased]: v5.0.3-beta001...HEAD
[5.0.3-beta001]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-beta001
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
[Unreleased]: v5.0.3-alpha10...HEAD
[5.0.3-alpha10]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-alpha10

### Fixed
- Issues with scaffolded code

- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
simon-reynolds added a commit that referenced this pull request Aug 9, 2021
## [5.0.3-beta005] - 2021-08-09

### Fixed
- Fix formatting of Nullable parameters - [@LiteracyFanatic](https://github.com/LiteracyFanatic) - #106
- Handle nullablility correctly in snapshot generation - #107

- Issues with scaffolded code
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70

### Added
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98
- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
simon-reynolds added a commit that referenced this pull request Aug 17, 2021
## [5.0.3-beta006] - 2021-08-17

### Fixed
- Removed `DevelopmentDependency=true` as it was setting `IncludeAssets` to undesirable values when restoring package - #108

- Fix formatting of Nullable parameters - [@LiteracyFanatic](https://github.com/LiteracyFanatic) - #106
- Handle nullablility correctly in snapshot generation - #107
- Issues with scaffolded code
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
- Issues with scaffolded code
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
[Unreleased]: v5.0.3-beta005...HEAD
[5.0.3-beta005]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-beta005

### Added
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98
- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98
- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
simon-reynolds added a commit that referenced this pull request Oct 16, 2021
## [5.0.3] - 2021-10-16

- Translations for `isNull` to be evaluated in-database - #114

### Fixed
- Removed `DevelopmentDependency=true` as it was setting `IncludeAssets` to undesirable values when restoring package - #108
- Fix formatting of Nullable parameters - [@LiteracyFanatic](https://github.com/LiteracyFanatic) - #106
- Handle nullablility correctly in snapshot generation - #107
- Issues with scaffolded code
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
- Issues with scaffolded code
- Improved code generation for contexts scaffolded from an existing database - #89
- Correct issue with InsertData operations and 2D arrays
- Generate valid code in HasData method
- Fix issue with generated DbContext members in scaffolded code
- Resolved issue with migrations have a missing unit arg to the Up method if no changes in model
- Foreign Key constraints now created correctly
- Fix indentation issue when table has constraints - #75
- Constraints now correctly generated - #72
- Generated Migrations will now always include the System namespace - #70
[Unreleased]: v5.0.3-beta005...HEAD
[5.0.3-beta005]: https://github.com/efcore/EFCore.FSharp/releases/tag/v5.0.3-beta005

### Added
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98
- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
- Single case union support - [@lucasteles](https://github.com/lucasteles) - #98
- Query translation for Option types - [@lucasteles](https://github.com/lucasteles) - #93
- DbSet/IQueryable helpers to deal with EF Core async and nullable methods - [@lucasteles](https://github.com/lucasteles) - #94
- Automatic registration of DesignTimeServices - #86
- DbContextHelpers - curried functions for interacting with DbContext to allow for a more 'native' F# experience
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants