how to correctly create DbSet property in .net core applications

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

Question

I have this simple .net core class library project and trying code first approach for CRUD.

Here is my code:

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("");
        }
    }
}

In the statement public DbSet<Patient> Patients the property name Patients is showing as the below error:

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

I am not finding anywhere why this error is showing.

1
1
5/13/2018 8:47:22 PM

Accepted Answer

Without seeing it, I'm assuming your Patient model is missing it's public accessor tag. As a reminder, if it's not specified then the default is internal.

1
5/13/2018 8:03:54 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow