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

后端 未结 7 1040
伪装坚强ぢ
伪装坚强ぢ 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:43

    This error happens immediately after I enabled C# 8 nullable feature in my Entity Framework Core 3.1 project.

    The solution is to change your entity properties to their nullable counterparts. For example,

    Change from:

    public class Person {
      public int Id { get; set; }
      public string Name { get;set; }
      public string Address { get;set; }
    }
    
    

    To:

    public class Person {
      public int Id { get; set; }
      public string Name { get;set; }
      public string? Address { get;set; }  //change address to nullable string since it is nullable in database
    }
    
    

提交回复
热议问题