Data is Null. This method or property cannot be called on Null values

后端 未结 7 1037
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 20:07

I\'m working on an application where one can get information on movies from a database as well as add, update and delete the movies. In the database I have three tables (Movie,

7条回答
  •  无人及你
    2021-02-06 20:54

    In my case I was using EF Core and the issue was that the field was nullable in the database but in the ModelCreating it was required like that:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
       modelBuilder.Entity(entity =>
       {
          entity.Property(e => e.Details)
                        .IsRequired()
                        .HasMaxLength(250);
       }
    }
    

    I remove the IsRequired() and it worked fine.

    Update few days after, Got same issue, a string field It was not allowing null in the DB.

提交回复
热议问题