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

Fix indentation #75

Merged
merged 2 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- Fix indentation issue when table has constraints - https://github.com/efcore/EFCore.FSharp/pull/75

## [5.0.3-alpha5] - 2021-03-31

### Fixed
Expand Down
3 changes: 1 addition & 2 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ For this example we will use record types, but "normal" classes will also work i
type BloggingContext() =
inherit DbContext()

[<DefaultValue>] val mutable blogs : DbSet<Blog>
member __.Blogs with get() = __.blogs and set v = __.blogs <- v
member val Blogs : DbSet<Blog> = null with get, set

override __.OnConfiguring(options: DbContextOptionsBuilder) : unit =
options.UseSqlite("Data Source=blogging.db") |> ignore
Expand Down
4 changes: 1 addition & 3 deletions docsSrc/How_Tos/Use_DbContextHelpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ type Blog = {
type MyContext () =
inherit DbContext()

[<DefaultValue>]
val mutable private _blogs : DbSet<Blog>
member this.Blogs with get() = this._blogs and set v = this._blogs <- v
member val Blogs : DbSet<Blog> = null with get, set
```

We can use the helper methods like so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,19 @@ type FSharpMigrationOperationGenerator (code : ICSharpHelper) =
sb

let annotations (annotations: Annotation seq) (sb:IndentedStringBuilder) =
annotations
|> Seq.iter(fun a ->
sb
|> appendEmptyLine
|> append (sprintf ".Annotation(%s, %s)" (code.Literal a.Name) (code.UnknownLiteral a.Value))
|> ignore
)
sb

let lines =
annotations
|> Seq.map (fun a -> sprintf ".Annotation(%s, %s)" (code.Literal a.Name) (code.UnknownLiteral a.Value))

sb |> appendLines lines true

let oldAnnotations (annotations: Annotation seq) (sb:IndentedStringBuilder) =
annotations
|> Seq.iter(fun a ->
sb
|> appendEmptyLine
|> append (sprintf ".OldAnnotation(%s, %s)" (code.Literal a.Name) (code.UnknownLiteral a.Value))
|> ignore
)
sb
let lines =
annotations
|> Seq.map (fun a -> sprintf ".OldAnnotation(%s, %s)" (code.Literal a.Name) (code.UnknownLiteral a.Value))

sb |> appendLines lines true

let generateMigrationOperation (op:MigrationOperation) (sb:IndentedStringBuilder) :IndentedStringBuilder =
invalidOp ((op.GetType()) |> DesignStrings.UnknownOperation)
Expand Down Expand Up @@ -375,7 +370,7 @@ type FSharpMigrationOperationGenerator (code : ICSharpHelper) =
let writeConstraints sb =

let hasConstraints =
notNull op.PrimaryKey || (op.UniqueConstraints |> Seq.isEmpty |> not) || (op.ForeignKeys |> Seq.isEmpty |> not)
notNull op.PrimaryKey && (op.UniqueConstraints |> Seq.isEmpty |> not) && (op.ForeignKeys |> Seq.isEmpty |> not)

if hasConstraints then

Expand All @@ -386,16 +381,14 @@ type FSharpMigrationOperationGenerator (code : ICSharpHelper) =
|> ignore

if notNull op.PrimaryKey then

let pkName = op.PrimaryKey.Name |> code.Literal
let pkColumns = op.PrimaryKey.Columns |> Seq.map(fun c -> map.[c]) |> Seq.toList |> code.Lambda

sb
|> append "table.PrimaryKey("
|> append (op.PrimaryKey.Name |> code.Literal)
|> append ", "
|> append (op.PrimaryKey.Columns |> Seq.map(fun c -> map.[c]) |> Seq.toList |> code.Lambda)
|> append ")"
|> indent
|> append (sprintf "table.PrimaryKey(%s, %s)" pkName pkColumns)
|> annotations (op.PrimaryKey.GetAnnotations())
|> appendLine " |> ignore"
|> unindent
|> ignore

op.UniqueConstraints |> Seq.iter writeUniqueConstraint
Expand All @@ -404,6 +397,7 @@ type FSharpMigrationOperationGenerator (code : ICSharpHelper) =
sb
|> unindent
|> appendLine ") "
|> unindent
else
sb

Expand Down
12 changes: 2 additions & 10 deletions src/EFCore.FSharp/Scaffolding/FSharpDbContextGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,12 @@ type FSharpDbContextGenerator
let generateDbSet (sb:IndentedStringBuilder) (entityType : IEntityType) =

let dbSetName = entityDbSetName entityType
let mutableName = "_" + dbSetName

sb
|> appendLine "[<DefaultValue>]"
|> appendLine (sprintf "val mutable private %s : DbSet<%s>" mutableName entityType.Name)
|> appendLine (sprintf "member this.%s" dbSetName)
|> indent
|> appendLine (sprintf "with get() = this.%s" mutableName)
|> appendLine (sprintf "and set v = this.%s <- v" mutableName)
|> unindent
|> appendLine (sprintf "member val %s: DbSet<%s> = null with get, set" dbSetName entityType.Name)
|> appendEmptyLine
|> ignore

sb.AppendLine() |> ignore

let generateDbSets (model:IModel) (sb:IndentedStringBuilder) =

model.GetEntityTypes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,7 @@ type MyMigration() =
inherit Migration()

override this.Up(migrationBuilder:MigrationBuilder) =
migrationBuilder.Sql("-- TEST")
.Annotation("Some:EnumValue", RegexOptions.Multiline) |> ignore
migrationBuilder.Sql("-- TEST").Annotation("Some:EnumValue", RegexOptions.Multiline) |> ignore

migrationBuilder.AlterColumn<Database>(
name = "C1"
Expand Down