efcore / EFCore.FSharp

Adds F# design-time support to EF Core
MIT License
234 stars 26 forks source link

Module opening is not generated for an entities for migrations #84

Closed rstm-sf closed 3 years ago

rstm-sf commented 3 years ago

Describe the bug Module opening is not generated for an entities for migrations

To Reproduce Steps to reproduce the behavior:

  1. dotnet new -i "giraffe-template::*"
  2. dotnet new giraffe -o smthProject
  3. https://github.com/efcore/EFCore.FSharp/blob/master/GETTING_STARTED.md#add-design-time-services-interface-to-our-codebase
  4. ...
<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <AssemblyName>Giraffe.App</AssemblyName>
        <EnableDefaultContentItems>false</EnableDefaultContentItems>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="EntityFrameworkCore.FSharp" Version="5.0.3-alpha9" />
        <PackageReference Include="Giraffe" Version="5.0.0-rc-6" />
        <PackageReference Include="Giraffe.ViewEngine" Version="1.3.*" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
        <PackageReference Include="Ply" Version="0.3.*" />
    </ItemGroup>

    <ItemGroup>
        <Compile Include="DesignTimeServices.fs" />
        <Compile Include="Entities.fs" />
        <Compile Include="BloggingContext.fs" />
        <Compile Include="Migrations\20210507180335_Initial.fs" />
        <Compile Include="Migrations\BloggingContextModelSnapshot.fs" />
        <Compile Include="Program.fs" />
    </ItemGroup>

    <ItemGroup>
        <None Include="web.config" CopyToOutputDirectory="PreserveNewest" />
        <Content Include="WebRoot\**\*">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>
</Project>
module Giraffe.Entities

open System.ComponentModel.DataAnnotations
open Microsoft.AspNetCore.Identity

[<AllowNullLiteral>]
type StoreUser() =
    inherit IdentityUser()
    member val FirstName = "" with get, set
    member val LastName = "" with get, set

type [<CLIMutable>] Order =
    {
        [<Key>] Id : int
        OrderNumber : string
        [<DefaultValue>] User : StoreUser
    }
module Giraffe.BloggingContext

open Giraffe.Entities
open Microsoft.EntityFrameworkCore

type BloggingContext () =
    inherit DbContext()

    member _.Orders : DbSet<Order> = Unchecked.defaultof<DbSet<Order>>

    override _.OnConfiguring (options: DbContextOptionsBuilder) =
        options.UseSqlite("Data Source=blogging.db") |> ignore

    override _.OnModelCreating (modelBuilder : ModelBuilder) =
        base.OnModelCreating(modelBuilder)

        modelBuilder
            .Entity<Order>()
            .HasData({
                Id = 1
                OrderNumber = "12345" })
            |> ignore

Expected behavior dotnet ef database update will execute successfully

Screenshots image

simon-reynolds commented 3 years ago

Hi @rstm-sf Thank you for the excellent bug report! I'll reproduce this and see how soon I can get a fix out

simon-reynolds commented 3 years ago

Hi @rstm-sf I haven't been able to reproduce this locally using the latest changes, I was able to run dotnet ef database update successfully Can you try updating to https://www.nuget.org/packages/EntityFrameworkCore.FSharp/5.0.3-beta001 please?

This release removes the requirement to implement DesignTimeServices.fs yourself so you can remove that file from your project now

rstm-sf commented 3 years ago

5.0.3-beta001

I'm fine with this version too. Thank you!