问题描述
请帮助我。我有一个文件ImageContext:
using System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Data.Entity;
命名空间userGallery.Models
{
public class ImageContext:DbContext
{
public DbSet< Image>图片{get;组; }
}
}
我创建新的模型幻灯片并添加字符串连接ImageContext。
结果
...
public class ImageContext:DbContext
{
public DbSet< Image>图片{get;组; }
public DbSet< Slide>幻灯片{get;组; }
}
...
如何更新数据库以创建表幻灯片?
屏幕数据库表:
如果您有自动迁移设置,这应该很直接。 / p>
如果没有,您需要运行
启用-Migrations -EnableAutomaticMigrations
也许先进一步阅读这里:
-
添加幻灯片创建新的迁移
添加迁移SlideMigration
-
现在做一个更新...希望它应该都可以工作。
Please, help me.I had a file ImageContext:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace userGallery.Models
{
public class ImageContext : DbContext
{
public DbSet<Image> Images { get; set; }
}
}
I create new model Slide and add string connect in ImageContext.Result
...
public class ImageContext : DbContext
{
public DbSet<Image> Images { get; set; }
public DbSet<Slide> Slides { get; set; }
}
...
How to update database to create a table Slides?
Screenshoot database table:enter image description here
If you have automatic migrations set up this should be pretty straight forward.
If you haven't, you will need to run
Enable-Migrations –EnableAutomaticMigrations
Perhaps do some further reading here first though: http://msdn.microsoft.com/en-gb/data/jj554735.aspx
Create a new migration with the addition of Slides
Add-Migration "SlideMigration"
Now do an update... and hopefully it should all work.
Update-Database
这篇关于如何在上下文ASP.NET MVC中添加新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!