-
Notifications
You must be signed in to change notification settings - Fork 28
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
.NET 6 - EnsureCreated creates all fields nullable #120
Comments
Hi @Ciantic |
@simon-reynolds I was just wondering how these can even differ between C# and F#? The C# must be pre-configuring the EF somehow, I'd like to configure F# similarily so that all fields are NOT NULL. I suspect the reason EF does this now, is because it detects I want same behavior in F#, do you know how? Thanks. |
You can get the same behaviour for now by using Attributes on the Person record like so [<CLIMutable>]
type Person =
{ Id : Guid
[<Required>]
FirstName : string
[<Required>]
LastName : string
[<Required>]
Address : string
[<Required>]
City : string} I'm looking now at how to define this behaviour by default and hope to have a fix for this in the coming days |
I recently refactored a project of mine to use the following snippet in for entity in modelBuilder.Model.GetEntityTypes() do
for property in entity.ClrType.GetProperties() do
if property.GetType() = typeof<string> then
modelBuilder.Entity(property.DeclaringType)
.Property(property.PropertyType, property.Name)
.IsRequired()
|> ignore Could something like this be included by default when calling |
Hi @simon-reynolds This problem arises from the fact that: The entity model defines by C# code that cannot be modified by myself, such as I see that all string type properties generate not null type columns. Then when registering a user, the database reports an error because I've tried using |
Describe the bug
I'm using .NET 6, so this might be something new. With C# I get all fields as
NOT NULL
, but with F# all fields are nullable. Code is practically same, here is F# code:E.g. F# code:
I get this in the command line as I start:
Expected behavior
It's notable that both projects (C# csproj and F# fsproj) project has these settings:
I suspect the C# somehow configs everything non-nullable because of that, but I can't replicate this in F# side.
The text was updated successfully, but these errors were encountered: