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

Migration not generated due to optional single case DU #142

Open
brud opened this issue Jul 23, 2022 · 1 comment
Open

Migration not generated due to optional single case DU #142

brud opened this issue Jul 23, 2022 · 1 comment

Comments

@brud
Copy link

brud commented Jul 23, 2022

Describe the bug
Migration not generated due to single DU (PageId)

To Reproduce

module Database

open System.ComponentModel.DataAnnotations
open System.ComponentModel.DataAnnotations.Schema
open Microsoft.EntityFrameworkCore
open EntityFrameworkCore.FSharp.Extensions
open Microsoft.EntityFrameworkCore.Design

type ContentId = ContentId of int
type PageId = PageId of int

// some other entities

[<CLIMutable>]
type Content = {
    [<Key>] Id: ContentId
    PageId: PageId option
    ParentId: int option
    [<NotMapped>]
    Parent: Content optional
}

type ConstructorContext(options : DbContextOptions<ConstructorContext>) =
    inherit DbContext(options)

    [<DefaultValue>] val mutable contents : DbSet<Content>
    member this.Contents with get() = this.contents and set v = this.contents <- v

    override _.OnModelCreating builder =
        builder.RegisterOptionTypes() // enables option values for all entities
        builder.RegisterSingleUnionCases() // enables single case unions for all entities

    override _.OnConfiguring(options: DbContextOptionsBuilder) : unit =
        options
            .UseNpgsql(connectionString)
            .UseFSharpTypes() // enable queries for F# types
        |> ignore

type ApplicationDbContextFactory() =
    interface IDesignTimeDbContextFactory<ConstructorContext> with
        member _.CreateDbContext (_: string[]) =
            let optionsBuilder = DbContextOptionsBuilder<ConstructorContext>()
            optionsBuilder.UseNpgsql(connectionString)
            |> ignore
            new ConstructorContext(optionsBuilder.Options)

I have an Exception after dotnet ef migrations add Init

The property 'Content.PageId' is of type 'PageId' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder. Ignore' in 'OnModelCreating'.

UPD.: as I can see, this error appears only if field is single DU AND option

UPD. [2]: when I try to create Parent optional field (with NotMapped attribute) i get an error:
The property 'Content.Parent' is of type 'Content' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder .Ignore' in 'OnModelCreating'.
But if I remove option - the errror dissapears.

@brud brud changed the title Migration not generated due to single DU Migration not generated due to optional single case DU Jul 25, 2022
@brud
Copy link
Author

brud commented Aug 19, 2022

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant