Page 1 of 1

BUG FOUND: Column always required when set to null

Posted: Sat 22 May 2021 15:09
by RobertK
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" />

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

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

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

Posted: Wed 26 May 2021 18:17
by RobertK
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

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

Posted: Fri 09 Jul 2021 09:21
by Shalex
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.

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

Posted: Sun 01 May 2022 16:45
by RobertK
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.

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

Posted: Mon 02 May 2022 01:51
by RobertK
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.