Open eastwing27 opened 2 years ago
Ok, so the problem seems to be deeper as I can not see any way to create an optional relation in F# way at all! If I remove nav property, the EF keeps generating extra ModelId1 prop. At the moment, the only thing that seems to work for me is removing navigation property at all and using Nullable
Is it possible no one faced that problem before? I thought it is something trivial. Or am I duplicating the question? I couldn't find it. If I do, please, point me to the answered one.
@eastwing27 I have just start to take a look at efcore/EFCore.FSharp for a new project and this is the first problem I have hit.
I have play around with the ScaffoldOptions
and best I could do was setting ScaffoldNullableColumnsAs = ScaffoldNullableColumnsAs.NullableTypes
which creates code that complies but doesn't run with adding .IsRequired(false)
to the modelBuilder
[<CLIMutable>]
type Lookup = {
Id: int
LookupValue: string
Tests: Test seq
}
[<CLIMutable>]
type Test = {
Id: int
LookupId: Nullable<int>
Name: string
Lookup: Lookup
}
However this is a massive hack because even though the code runs the record types are sort of hack/nullable and f# doesn't expect them to be
let db = new BlogTestContext()
let result = db.Tests.AsQueryable().ToList() |> Seq.head
if result.Lookup = null || isNull result.Lookup then // Error FS0043 The type 'BlogTestDomain.Lookup' does not have 'null' as a proper value
()
if Object.ReferenceEquals(result.Lookup, null) then // Compiles
()
this is sort of a bit of a project killer :(
I'm trying to create Code First DB in F# project and I just can't solve this problem. The idea is to create an optional relation and have a navigation property but if I have option property, EF won't create a migration:
If I ignore the property with Fluent API migration is created but it generates extra field and I get this warning:
Here is the examples of models:
In C#, adding virtual keyword would solve the issue, but is it possible with F#?