Entity Framework 7 Fluent API does not recognize IsOptional ()

I am currently setting up my database in my Asp.Net 5 project using the framework 7 entity previously with EF 6, when I wanted to make some of my columns null, I would use:

modelBuilder.Entity<Article>().Property(t => t.ArticleDateModified).IsOptional();

But it seems that it is IsOptionalno longer part of EF7, I was wondering how I can achieve the same using EF7?

Edit: Marc's answer is really correct, at first I did, although this worked because I found something like IsOptional:

builder.Entity<Article>().Property(t => t.ArticleDateModified).IsRequired(false);

But after I checked some test without it, it set the database column to zero, as I marked it as nullable in my domain model:

public DateTime? ArticleDateModified { get; set; }

, DateTime non-nullable IsRequired(false), :

"ArticleDateModified" "Article" nullable/optional, - "DateTime", NULL. /, , /.

, IsRequired(false) , , , , - ?

+4
2

, . :

, CLR- , . Entity Framework.

, , , GitHub, :

, NULL, , , -nullable, . , , , null, null, . EF6, . [ ]


: EF7 NULL . NULL, NULL, IsRequired.


OP

, API IsRequired(bool). , , EF6 IsOptional():

.IsOptional() - Required (false)
.IsRequired() - ()

, , . (Per update), IsRequired(false) , nullable, , .

, API : IsRequired(bool) IsRequired(), IsRequired(bool required = true). , .

+5

Em... nullable?

class Article
{
    public DateTime? ArticleDateModified {get;set;}
}
+3

Source: https://habr.com/ru/post/1621204/


All Articles