Skip to content

Commit

Permalink
Merge pull request #70 from efcore/fix-generated-namespaces
Browse files Browse the repository at this point in the history
Always include System namespace in generated Migrations
  • Loading branch information
simon-reynolds authored Mar 31, 2021
2 parents e56a910 + f021aa0 commit a0ceaba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
48 changes: 19 additions & 29 deletions src/EFCore.FSharp/Migrations/Design/FSharpMigrationsGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,30 @@ type FSharpMigrationsGenerator(dependencies, fSharpDependencies : FSharpMigratio
let mutable tempDownOperations = list.Empty
let mutable tempMigrationName = String.Empty

let getDefaultNamespaces (contextType: Type) =
seq {
"System"
"Microsoft.EntityFrameworkCore"
"Microsoft.EntityFrameworkCore.Infrastructure"
"Microsoft.EntityFrameworkCore.Metadata"
"Microsoft.EntityFrameworkCore.Migrations"
"Microsoft.EntityFrameworkCore.Storage.ValueConversion"

if contextType.Namespace |> String.IsNullOrEmpty |> not then
contextType.Namespace
} |> Seq.toList

member private this.GenerateMigrationImpl (migrationNamespace) (migrationName) (migrationId: string) (contextType:Type) (upOperations) (downOperations) (model) =
let sb = IndentedStringBuilder()

let allOperations = (upOperations |> Seq.append downOperations)

let operationNamespaces = this.GetNamespaces allOperations
let operationNamespaces = this.GetNamespaces allOperations |> Seq.toList

let namespaces =
[ "Microsoft.EntityFrameworkCore"
"Microsoft.EntityFrameworkCore.Infrastructure"
"Microsoft.EntityFrameworkCore.Metadata"
"Microsoft.EntityFrameworkCore.Migrations"
"Microsoft.EntityFrameworkCore.Storage.ValueConversion" ]
|> Seq.append operationNamespaces
|> Seq.append [contextType.Namespace]
|> Seq.filter (isNull >> not)
|> Seq.toList
(getDefaultNamespaces contextType @ operationNamespaces)
|> sortNamespaces
|> Seq.distinct

sb
|> appendAutoGeneratedTag
Expand Down Expand Up @@ -99,26 +105,10 @@ type FSharpMigrationsGenerator(dependencies, fSharpDependencies : FSharpMigratio
member private this.GenerateSnapshotImpl (modelSnapshotNamespace: string) (contextType: Type) (modelSnapshotName: string) (model: IModel) =
let sb = IndentedStringBuilder()

let defaultNamespaces =
seq {
"System"
"Microsoft.EntityFrameworkCore"
"Microsoft.EntityFrameworkCore.Infrastructure"
"Microsoft.EntityFrameworkCore.Metadata"
"Microsoft.EntityFrameworkCore.Migrations"
"Microsoft.EntityFrameworkCore.Storage.ValueConversion"

if contextType.Namespace |> String.IsNullOrEmpty |> not then
contextType.Namespace
}
|> Seq.toList

let modelNamespaces =
this.GetNamespaces model
|> Seq.toList
let modelNamespaces = this.GetNamespaces model |> Seq.toList

let namespaces =
(defaultNamespaces @ modelNamespaces)
(getDefaultNamespaces contextType @ modelNamespaces)
|> sortNamespaces
|> Seq.distinct

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ module FSharpMigrationsGeneratorTest =
let expectedCode = """// <auto-generated />
namespace MyNamespace
open System
open System.Text.RegularExpressions
open EntityFrameworkCore.FSharp.Test.Migrations.Design
open Microsoft.EntityFrameworkCore
Expand Down

0 comments on commit a0ceaba

Please sign in to comment.