C# 如何在.net核心应用程序中正确创建DbSet属性

C# 如何在.net核心应用程序中正确创建DbSet属性,c#,.net,asp.net-mvc,entity-framework,entity-framework-core,C#,.net,Asp.net Mvc,Entity Framework,Entity Framework Core,我有一个简单的.net核心类库项目,并尝试了针对CRUD的代码优先方法 这是我的密码: using System; using System.Collections.Generic; using System.Text; using EFDemoApp_Domain.Entities; using Microsoft.EntityFrameworkCore; namespace EFDemoApp_Domain.DataAccess { public class EFDemoAppDa

我有一个简单的.net核心类库项目,并尝试了针对CRUD的代码优先方法

这是我的密码:

using System;
using System.Collections.Generic;
using System.Text;
using EFDemoApp_Domain.Entities;
using Microsoft.EntityFrameworkCore;

namespace EFDemoApp_Domain.DataAccess
{
    public class EFDemoAppDataContext:DbContext
    {
        public EFDemoAppDataContext(DbContextOptions options):base(options)
        {

        }
        public DbSet<Patient> Patients { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("");
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用EFDemoApp_Domain.Entities;
使用Microsoft.EntityFrameworkCore;
命名空间EFDemoApp_Domain.DataAccess
{
公共类EFDemoAppDataContext:DbContext
{
公共EFDemoAppDataContext(DbContextOptions选项):基本(选项)
{
}
公共数据库集患者{get;set;}
配置时受保护的覆盖无效(DBContextOptions Builder Options Builder)
{
optionsBuilder.UseSqlServer(“”);
}
}
}
在语句
public DbSet Patients
中,属性名称
Patients
显示为以下错误:

严重性代码说明项目文件行抑制状态 错误CS0053可访问性不一致:属性类型“DbSet”的可访问性低于属性“EFDemoAppDataContext.Patients”


我找不到显示此错误的原因。

如果看不到它,我假设您的
患者
型号缺少其公共访问器标签。作为提醒,如果未指定,则默认值为
内部

显示您的患者模型。很可能你忘记公开了。@gilliduck谢谢,它不见了。添加了一个带有提醒的答案。@gilliduck我可以看出你没有侮辱任何人,请允许我推荐一种更高级的语言,即使是对你自己。“这似乎是你应得的。”吉利杜克同时,你对有用评论作者的ping似乎被打断了。如果你想让他们注意到,你可能必须再试一次。