首页 > 其他分享 >webapi DbContext DbSet null 警告解决

webapi DbContext DbSet null 警告解决

时间:2023-03-04 18:33:57浏览次数:52  
标签:webapi Customers DbSet DbContext null public

不需要去考虑表不存在情况,也就是不需要去判断 _db.Customers 是否为空。因为一般来说,数据库表肯定是有的。

public class NullableReferenceTypesContext : DbContext
{
    public DbSet<Customer> Customers => Set<Customer>();
    public DbSet<Order> Orders => Set<Order>();

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer(
                @"Server=(localdb)\mssqllocaldb;Database=EFNullableReferenceTypes;Trusted_Connection=True");
}

参考文档

使用可为 null 引用类型 - EF Core | Microsoft Learn

标签:webapi,Customers,DbSet,DbContext,null,public
From: https://www.cnblogs.com/cqlql/p/17178796.html

相关文章