efcore / EFCore.FSharp

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

AlterColumn operations included in what should be an empty migration #126

Closed simon-reynolds closed 2 years ago

simon-reynolds commented 2 years ago

A migration with no changes from the last should have no operations

Given the following context, add two migrations

namespace Test

open System
open System.Collections.Generic
open Microsoft.EntityFrameworkCore
open Microsoft.EntityFrameworkCore.Design
open Microsoft.EntityFrameworkCore.Metadata
open Microsoft.EntityFrameworkCore.Metadata.Builders
open EntityFrameworkCore.FSharp.Extensions

module rec Domain =
    [<AllowNullLiteral>]
    type Account() =
        [<DefaultValue>] val mutable private _Id: int
        [<DefaultValue>] val mutable private _CustomerId: int
        [<DefaultValue>] val mutable private _Customer: Customer
        member this.Id with get() = this._Id and set v = this._Id <- v
        member this.CustomerId with get() = this._CustomerId and set v = this._CustomerId <- v
        member this.Customer with get() = this._Customer and set v = this._Customer <- v

    [<AllowNullLiteral>]
    type Customer() =
        [<DefaultValue>] val mutable private _Id: int
        [<DefaultValue>] val mutable private _ProfileId: int
        [<DefaultValue>] val mutable private _Profile: Profile
        [<DefaultValue>] val mutable private _AddressId: int
        [<DefaultValue>] val mutable private _Address: Address
        member this.Id with get() = this._Id and set v = this._Id <- v
        member this.ProfileId with get() = this._ProfileId and set v = this._ProfileId <- v
        member this.Profile with get() = this._Profile and set v = this._Profile <- v
        member this.AddressId with get() = this._AddressId and set v = this._AddressId <- v
        member this.Address with get() = this._Address and set v = this._Address <- v

    [<AllowNullLiteral>]
    type Profile() =
        [<DefaultValue>] val mutable private _Id: int
        member this.Id with get() = this._Id and set v = this._Id <- v

    [<AllowNullLiteral>]
    type Address() =
        [<DefaultValue>] val mutable private _Id: int
        member this.Id with get() = this._Id and set v = this._Id <- v

    type LetsConnectContext() =
        inherit DbContext()

        [<DefaultValue>] val mutable private _Accounts : DbSet<Account>
        member this.Accounts with get() = this._Accounts and set v = this._Accounts <- v

        [<DefaultValue>] val mutable private _Customers : DbSet<Customer>
        member this.Customers with get() = this._Customers and set v = this._Customers <- v

        [<DefaultValue>] val mutable private _Profiles : DbSet<Profile>
        member this.Profiles with get() = this._Profiles and set v = this._Profiles <- v

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

        override __.OnConfiguring(options: DbContextOptionsBuilder) : unit =
            options.UseSqlServer(Environment.GetEnvironmentVariable("CONNECTION_STRING")) |> ignore

Expected behavior Second migration should be empty. Instead there are AlterColumn operations created for each Primary and Foreign Key

(Originally reported as part of #124 by @LiteracyFanatic )