I have a property called TotalVolume
which is a Double
. In the code-first approach when the database is constructed the property TotalVolume
has got a Not Null
value by default. I want to make the property TotalVolume
accept Null
values too.
I am using FluentAPI, and the change I made is as follows:
modelBuilder.Entity<Employee>()
.Property(p => p.TotalVolume)
.IsRequired(false);
I end up with the following error when I Add-Migration
:
The property 'TotalVolume' on entity type 'Employee' cannot be marked as nullable/optional because the type of the property is 'double' which is not a nullable type. Any property can be marked as non-nullable/required, but only properties of nullable types and which are not part of primary key can be marked as nullable/optional.
Thereafter, I tried the following approach, where I made the following change in my Employee
Model.
public double? TotalVolume{ get; set; }
However, when I updated the database, the datatype for TotalVolume
has changed to a float
. I want the datatype to still remain as double
.
float
in SQL is a 64bit value and corresponds to double
in .Net, so it seems to be working as expected.
Entity Framework maps these types so that they have the same meaning but it doesn't require they have the same names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.