c# - 错误 CS0053 : Inconsistent Accessibility for DbSet Property in . NET Core Entity Framework - 如何解决?

标签 c# .net asp.net-mvc entity-framework entity-framework-core

我有这个简单的 .net core 类库项目,并尝试使用代码优先方法进行 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("");
        }
    }
}

在声明中public DbSet<Patient> Patients属性名称Patients显示如下错误:

Severity Code Description Project File Line Suppression State Error CS0053 Inconsistent accessibility: property type 'DbSet' is less accessible than property 'EFDemoAppDataContext.Patients'

我没有在任何地方找到显示此错误的原因。

最佳答案

如果没有看到它,我就假设您的 Patient 模型缺少其公共(public)访问器标记。提醒一下,如果未指定,则默认为内部

关于c# - 错误 CS0053 : Inconsistent Accessibility for DbSet Property in . NET Core Entity Framework - 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50317439/

相关文章:

asp.net - 您如何决定将模型数据从 asp.net mvc Controller 传递到 View 的方式?

asp.net-mvc - MVCSiteMapProvider 面包屑不正确的父节点 ID

c# - 如何告诉 JsonConvert.SerializeObject 将字符串对象视为 JSON

c# - ASCII + Numpad 组合为 power 10

.net - 如何查找 .NET 命名空间的程序集名称,例如 Microsoft.WindowsAzure.ServiceRuntime

c# - 使用变量中的常量动态生成 lambda 表达式

asp.net-mvc - 无法将子网格绑定(bind)到剑道层次结构 UI 网格中的第二行

c# - 添加带有 Identity asp.net core 的 UserClaim

c# - SqlCommand 是否优化了参数化的sql 语句?

C#:将文本文件内容与字符串变量进行比较