我知道这在过go 是一个问题,因为您可以在网络和SO上搜索so many questions有关从EF Core模型获取警告的信息.今天我第一次使用EF Core for .NET 8,我刚刚意识到警告不再存在:
public class AppDbContext : DbContext
{
public DbSet<DbAccount> Accounts { get; set; }
}
public class MyClass
{
// The line below still receives this warning:
// Warning CS8618 Non-nullable property 'Accounts' must contain a non-null value when exiting constructor.Consider declaring the property as nullable:
public DbSet<DbAccount> Accounts { get; set; }
}
有趣的是,它跳过了DbContext
而不是DbSet
类型本身的成员,正如您从上面的例子中可以看到的那样,我自己的类仍然收到CS 8618警告.
我try 过阅读DbContext
甚至DbSet
的反编译代码,但找不到任何特别的地方.EF Core团队如何做到这一点?我可以以某种方式将其应用到我自己的类中吗(例如POCO杨森类)?