Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 支持';EFDbContext';自创建数据库以来,上下文已更改_C#_Sql_Linq_Entity Framework_Asp.net Mvc 5 - Fatal编程技术网

C# 支持';EFDbContext';自创建数据库以来,上下文已更改

C# 支持';EFDbContext';自创建数据库以来,上下文已更改,c#,sql,linq,entity-framework,asp.net-mvc-5,C#,Sql,Linq,Entity Framework,Asp.net Mvc 5,我的sql数据库表和实体框架数据库上下文和模型类正确,但我得到的上下文已更改错误: Additional information: The model backing the 'EFDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?Lin

我的sql数据库表和实体框架数据库上下文和模型类正确,但我得到的上下文已更改错误:

Additional information: The model backing the 'EFDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
我的桌子看起来像这样:

CREATE TABLE [dbo].[Jamies] (
    [JamesID] INT            IDENTITY (1, 1) NOT NULL,
    [Name]   NVARCHAR (255) NOT NULL,
    CONSTRAINT [PK_dbo.Jamies] PRIMARY KEY CLUSTERED ([JamesID] ASC)
);
class EFDbContext : DbContext
{
    public DbSet<AppInformation> AppInformation { get; set; }
    //public DbSet<Revision> Revisions { get; set; }

    public DbSet<James> Jamies{ get; set; }
}
public class James
{
    [Key]
    public int JamesID { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; }
}
public class EFJamesRepository : IJamesRepository
{
    private EFDbContext context = new EFDbContext();

    public IQueryable<James> Jamies
    {
        get { return context.Jamies; }
    }
...
public class JamesController : Controller
{
    private IJamesRepository repository;
    public int PageSize = 2;

    public JamesController(IJamesRepository repo)
    {
        repository = repo;
    }

    public ViewResult List(int page = 1)
    {
        JamiesListViewModel model = new JamiesListViewModel
        {
            Jamies = repository.Jamies
                .OrderBy(s => s.Name)
                .Skip((page - 1) * PageSize)
                .Take(PageSize),
            PagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = repository.Jamies.Count()
            }
        };
        return View(model);
    }
我的EFDbContext类如下所示:

CREATE TABLE [dbo].[Jamies] (
    [JamesID] INT            IDENTITY (1, 1) NOT NULL,
    [Name]   NVARCHAR (255) NOT NULL,
    CONSTRAINT [PK_dbo.Jamies] PRIMARY KEY CLUSTERED ([JamesID] ASC)
);
class EFDbContext : DbContext
{
    public DbSet<AppInformation> AppInformation { get; set; }
    //public DbSet<Revision> Revisions { get; set; }

    public DbSet<James> Jamies{ get; set; }
}
public class James
{
    [Key]
    public int JamesID { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; }
}
public class EFJamesRepository : IJamesRepository
{
    private EFDbContext context = new EFDbContext();

    public IQueryable<James> Jamies
    {
        get { return context.Jamies; }
    }
...
public class JamesController : Controller
{
    private IJamesRepository repository;
    public int PageSize = 2;

    public JamesController(IJamesRepository repo)
    {
        repository = repo;
    }

    public ViewResult List(int page = 1)
    {
        JamiesListViewModel model = new JamiesListViewModel
        {
            Jamies = repository.Jamies
                .OrderBy(s => s.Name)
                .Skip((page - 1) * PageSize)
                .Take(PageSize),
            PagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = repository.Jamies.Count()
            }
        };
        return View(model);
    }
JamesRepository如下所示:

CREATE TABLE [dbo].[Jamies] (
    [JamesID] INT            IDENTITY (1, 1) NOT NULL,
    [Name]   NVARCHAR (255) NOT NULL,
    CONSTRAINT [PK_dbo.Jamies] PRIMARY KEY CLUSTERED ([JamesID] ASC)
);
class EFDbContext : DbContext
{
    public DbSet<AppInformation> AppInformation { get; set; }
    //public DbSet<Revision> Revisions { get; set; }

    public DbSet<James> Jamies{ get; set; }
}
public class James
{
    [Key]
    public int JamesID { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; }
}
public class EFJamesRepository : IJamesRepository
{
    private EFDbContext context = new EFDbContext();

    public IQueryable<James> Jamies
    {
        get { return context.Jamies; }
    }
...
public class JamesController : Controller
{
    private IJamesRepository repository;
    public int PageSize = 2;

    public JamesController(IJamesRepository repo)
    {
        repository = repo;
    }

    public ViewResult List(int page = 1)
    {
        JamiesListViewModel model = new JamiesListViewModel
        {
            Jamies = repository.Jamies
                .OrderBy(s => s.Name)
                .Skip((page - 1) * PageSize)
                .Take(PageSize),
            PagingInfo = new PagingInfo
            {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = repository.Jamies.Count()
            }
        };
        return View(model);
    }
有什么想法吗?

添加

Database.SetInitializer<EFDbContext>(null);
Database.SetInitializer(null);
转到Global.asax文件以禁用ef迁移。
您似乎出于某种原因启用了迁移。

快速修复,删除数据库并运行程序。。否则请使用DatabaseMigration可能重复的