I'm currently setting up my database in my Asp.Net 5 project using entity framework 7, previously with EF 6, when I wanted to make some of my columns nullable, I would use:
modelBuilder.Entity<Article>().Property(t => t.ArticleDateModified).IsOptional();
But it seems that IsOptional
is not part of EF7 anymore, I was wondering how can I achieve the same thing using EF7?
Edit:
Marc's answer is indeed correct, first I though it worked because I found something that was like IsOptional
:
builder.Entity<Article>().Property(t => t.ArticleDateModified).IsRequired(false);
But after I ran some test without it, it set the database column nullable because I marked it as nullable in my domain model:
public DateTime? ArticleDateModified { get; set; }
Also worth to note that when I made the DateTime
non-nullable and used the IsRequired(false)
, I got the following error:
The property 'ArticleDateModified' on entity type 'Article' cannot be marked as nullable/optional because the type of the property is 'DateTime' 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.
so, I wonder what is the use of IsRequired(false)
here if all I have to do to make a database column nullable is to make it nullable in my domain class?