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

The migrations generate F# code in a C# project #110

Open
lucasteles opened this issue Aug 17, 2021 · 2 comments
Open

The migrations generate F# code in a C# project #110

lucasteles opened this issue Aug 17, 2021 · 2 comments

Comments

@lucasteles
Copy link
Contributor

lucasteles commented Aug 17, 2021

I'm working in a project that mix F# and C#, today the DbContext is in the C# part,
I would like to use some of the features of this package, but the generated migration is a mix of C# and F# (which does not compile)

    public partial class escola : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name = "Escolas"
                ,columns = (fun table -> 
                {|
                    Id =
                        table.Column<Guid>(
                            nullable = false
                            ,``type`` = "uuid"
                        )
                    Nome =
                        table.Column<string>(
                            nullable = true
                            ,``type`` = "character varying(200)"
                            , maxLength = Nullable(200))
                    IdUsuarioAdmin =
                        table.Column<string>(
                            nullable = true
                            ,``type`` = "text"
                        )
                |})
                ,constraints =
                    (fun table -> 
                        table.PrimaryKey("PK_Escolas", (fun x -> (x.Id) :> obj)) |> ignore
                        table.ForeignKey(
                            name = "FK_Escolas_AspNetUsers_IdUsuarioAdmin",
                            column = (fun x -> (x.IdUsuarioAdmin) :> obj)
                            ,principalTable = "AspNetUsers"
                            ,principalColumn = "Id"
                            ,onDelete = ReferentialAction.Restrict
                            ) |> ignore

                    ) 
            ) |> ignore

            migrationBuilder.CreateIndex(
                name = "IX_Escolas_IdUsuarioAdmin"
                ,table = "Escolas"
                ,column = "IdUsuarioAdmin"
                ) |> ignore


        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name = "Escolas"
                ) |> ignore


        }
    }
}

The is any way to workaround this?
Should this package discover is the project is a F# project?
Or should we have a configuration for that?

@simon-reynolds
Copy link
Collaborator

Hi @lucasteles

Currently the EntityFrameworkCore.FSharp.props file should only register EFCoreFSharpServices if the project it's installed into is an F# project.

A possible workaround would be to register your own implementation of IDesignTimeServices that restores the default c# generators
Looking at EFCoreFSharpServices.fs, simply replacing every instance of FSharp with CSharp and removing ScaffoldOptions and FSharpMigrationsGeneratorDependencies should do the job

@bricelam
Copy link
Member

Hmm... this bug might belong in dotnet/efcore. I wouldn't be surprised if I accidentally used the startup project's language instead of the target/migrations project's language.

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

3 participants