问题描述
我只是一个小问题,我为迁移和数据库构建了上下文类,这是我的上下文类
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataLayer
{
public class MydbContext:DbContext
{
public DbSet<group_page> Group_Pages { get; set; }
public DbSet<Page> Pages { get; set; }
public DbSet<camment_page> camment_Pages { get; set; }
}
}
在创建数据库之后我想创建界面我意识到我忘记了公开我的班级 当我公开我的班级道具时,它们的名称和
是错误的inconsistent accessibility property type is less accessible
现在我不知道是否可以在不删除上下文和迁移的情况下解决此问题?
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace DataLayer
{
class group_page
{
[Key]
public int GroupID { get; set; }
[display(Name ="topic")]
[required(ErrorMessage ="pleas insert {0} ")]
[MaxLength(150)]
public string groupTitle { get; set; }
///navigation proprty
///
public virtual List<Page> Page { get; set; }
public group_page()
{
}
}
这是迁移类
namespace DataLayer.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<DataLayer.Context.MydbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(DataLayer.Context.MydbContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data.
}
}
}
解决方法
出现在 DbSet 括号中的其他类不是公开的
例如你有
class Page ...
你不能在像这样的道具中使用它:
public class Whatever{
public DbSet<Page> ...
不生成“属性类型不易访问”
看到这个小提琴 for example 显示了错误,然后当你把 class X
变成 public class X
时看着错误消失