BUG FOUND: Column always required when set to null

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
RobertK
Posts: 111
Joined: Thu 02 Mar 2017 05:44

BUG FOUND: Column always required when set to null

Post by RobertK » Sat 22 May 2021 15:09

v6.11.1219

Download zip file: https://filebin.net/t4kbp61pvwd7tnbq


Tried using regenerate storage and remapping, this should fix the issue, but it does not fix this issue?

ApplicationDbContext.cs: the error occurs in the address table, column "name", the model displays name is nullable, when the code is generated "name" is always required (line 130)

Generated code:
"modelBuilder.Entity<Address>().Property(x => x.Name).HasColumnName(@"Name").IsRequired().ValueGeneratedNever();"

It should be:
modelBuilder.Entity<Address>().Property(x => x.Name).HasColumnName(@"Name").ValueGeneratedNever();

Code: Select all

        private void AddressMapping(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Address>().ToTable(@"Addresses", @"public");
            modelBuilder.Entity<Address>().Property(x => x.Id).HasColumnName(@"Id").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Address>().Property(x => x.AccountId).HasColumnName(@"AccountId").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Address>().Property(x => x.Name).HasColumnName(@"Name").IsRequired().ValueGeneratedNever();
            modelBuilder.Entity<Address>().Property(x => x.Company).HasColumnName(@"Company").ValueGeneratedNever();
  ......
        }
Note
---------
EntityDeveloper should update the efml file from not-null="True" to not-null="False" but it does not do this (even when the model is regenerated using "regenerate storage and remapping" option)

Code: Select all

    <property name="Name" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="e4076478-def9-42fe-9d3c-a7b3bf68b179">
      <column name="" not-null="True" p1:unicode="True" />

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: BUG FOUND: Column always required when set to null

Post by Shalex » Tue 25 May 2021 12:47

We will fix the functionality of Regenerate Storage and Mapping Wizard in EF Core Model and notify you.

RobertK
Posts: 111
Joined: Thu 02 Mar 2017 05:44

Re: BUG FOUND: Column always required when set to null

Post by RobertK » Wed 26 May 2021 18:17

Shalex wrote: Tue 25 May 2021 12:47 We will fix the functionality of Regenerate Storage and Mapping Wizard in EF Core Model and notify you.
Thanks

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: BUG FOUND: Column always required when set to null

Post by Shalex » Fri 09 Jul 2021 09:21

The behavior of the Regenerate Storage and Mapping functionality in EF Core, NHibernate, and Telerik Data Access models is changed: the NOT NULL attribute of the column is reset to undefined now; after that, the behavior depends on the Nullable attribute of the property only.

New build of Entity Developer 6.11.1283 is available for download now: viewtopic.php?f=32&t=47208.

RobertK
Posts: 111
Joined: Thu 02 Mar 2017 05:44

Re: BUG FOUND: Column always required when set to null

Post by RobertK » Sun 01 May 2022 16:45

There is still a bug in in the class models code generated by devart entity developer

The class models generated does not set nullible columns to null (question mark symbol) When the column are not set to nullible, Dotnet ef migration will set the column to required, see link below.

----
https://docs.microsoft.com/en-us/ef/cor ... onventions
By convention, a property whose .NET type can contain null will be configured as optional, whereas properties whose .NET type cannot contain null will be configured as required. For example, all properties with .NET value types (int, decimal, bool, etc.) are configured as required, and all properties with nullable .NET value types (int?, decimal?, bool?, etc.) are configured as optional.
Last edited by RobertK on Sun 01 May 2022 17:12, edited 1 time in total.

RobertK
Posts: 111
Joined: Thu 02 Mar 2017 05:44

Re: BUG FOUND: Column always required when set to null

Post by RobertK » Mon 02 May 2022 01:51

RobertK wrote: Sun 01 May 2022 16:45 There is still a bug in in the class models code generated by devart entity developer

The class models generated does not set nullible columns to null (question mark symbol) When the column are not set to nullible, Dotnet ef migration will set the column to required, see link below.

----
https://docs.microsoft.com/en-us/ef/cor ... onventions
By convention, a property whose .NET type can contain null will be configured as optional, whereas properties whose .NET type cannot contain null will be configured as required. For example, all properties with .NET value types (int, decimal, bool, etc.) are configured as required, and all properties with nullable .NET value types (int?, decimal?, bool?, etc.) are configured as optional.
Setting "Nullable Reference Types" to enable resolved this issue.

Post Reply