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 compilation issues in scaffolded code. (#118) #119

Merged
merged 1 commit into from
Nov 13, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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]
- Fix compilation errors in scaffolded Many-to-Many joins - https://github.com/efcore/EFCore.FSharp/pull/119

## [6.0.1] - 2021-11-10

### Fixed
Expand Down
27 changes: 27 additions & 0 deletions docsTool/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53237/",
"sslPort": 44367
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"docsTool": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
18 changes: 6 additions & 12 deletions src/EFCore.FSharp/Internal/FSharpHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -779,18 +779,12 @@ type FSharpHelper(relationalTypeMappingSource: IRelationalTypeMappingSource) =
else
lambdaIdentifier

StringBuilder()
.Append(sprintf "(fun %s -> " lambdaIdentifier')
.Append("(")
.Append(
String.Join(
", ",
(properties
|> Seq.map (fun p -> lambdaIdentifier' + "." + p))
)
)
.Append(") :> obj)")
|> string
let props =
properties
|> Seq.map (fun p -> lambdaIdentifier' + "." + p)
|> join ", "

sprintf "(fun %s -> (%s) :> obj)" lambdaIdentifier' props

member this.Literal(values: obj [,]) : string = this.literalArray2D values

Expand Down
31 changes: 20 additions & 11 deletions src/EFCore.FSharp/Scaffolding/FSharpDbContextGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ type FSharpDbContextGenerator
(if isNull fk.PrincipalToDependent then
""
else
code.Literal fk.PrincipalToDependent.Name)
(sprintf "fun p -> p.%s" fk.PrincipalToDependent.Name))
)

if not (fk.PrincipalKey.IsPrimaryKey()) then
Expand All @@ -512,8 +512,14 @@ type FSharpDbContextGenerator
else
""

let methodParams = code.Lambda(fk.Properties, "d")
lines.Add(sprintf ".HasForeignKey%s(%s)" typeParam methodParams)
let methodParams =
fk.Properties
|> Seq.map (fun p -> "d." + p.Name)
|> join ", "

lines.Add(
sprintf ".HasForeignKey%s(fun (d:%s) -> (%s) :> obj)" typeParam fk.DeclaringEntityType.Name methodParams
)

let defaultOnDeleteAction =
if fk.IsRequired then
Expand Down Expand Up @@ -545,14 +551,21 @@ type FSharpDbContextGenerator
sb |> append line |> ignore

sb |> appendLine terminator |> ignore

lines.Clear()

let generateForeignKeyConfigurationLines (foreignKey: IForeignKey) targetType identifier =
let annotations =
annotationCodeGenerator.FilterIgnoredAnnotations(foreignKey.GetAnnotations())
|> annotationsToDictionary

lines.Add(sprintf "(fun %s -> %s.HasOne<%s>().WithMany()" identifier identifier targetType)
lines.Add(
sprintf
"(fun (%s: Builders.EntityTypeBuilder<_>) -> %s.HasOne<%s>().WithMany()"
identifier
identifier
targetType
)

if not (foreignKey.PrincipalKey.IsPrimaryKey()) then
let principalKeyProps =
Expand All @@ -578,13 +591,9 @@ type FSharpDbContextGenerator
if foreignKey.DeleteBehavior <> defaultOnDeleteAction then
lines.Add $".OnDelete({code.Literal(foreignKey.DeleteBehavior)})"

if lines.Count = 1 then
lines.[0] <- lines.[0] + ")"
else
lines.Add(")")

generateAnnotations foreignKey annotations lines
writeLines ","
writeLines "),"


if not _entityTypeBuilderInitialized then
initializeEntityTypeBuilder skipNavigation.DeclaringEntityType sb
Expand Down Expand Up @@ -635,7 +644,7 @@ type FSharpDbContextGenerator
lines.Add $"j.HasKey({props})"

if explicitName then
lines.Add ".HasName({code.Literal(key.GetName())})"
lines.Add $".HasName({code.Literal(key.GetName())})"

generateAnnotations key keyAnnotations lines
writeLines " |> ignore"
Expand Down