[英]ASP.NET MVC 3 Music Store Tutorial
我正在使用MVC音乐商店教程应用程序。 我已经更改了应用程序的3个原始类名(重命名),即Genre,Album和Artist,并将它们分别命名为Categories,Brands和Types。
我已经更新了所有参考资料。 因此,在此之后,我拥有的是相同的应用程序和数据库值,但带有我想要的名称。
在作为种子类的SampleData.cs中,当我根据自己的要求向列表中添加新值时,我看不到数据库中反映出任何更改,并且在运行该应用程序时,再次显示了相同的值。
我的种子分类代码片段(仅分类)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcMusicStore.Models
{
public class SampleData : DropCreateDatabaseIfModelChanges<MusicStoreEntities>
{
protected override void Seed(MusicStoreEntities context)
{
var genres = new List<Categories>
{
new Categories { Name = "Guitars" },
new Categories { Name = "Keyboards" },
new Categories { Name = "Drums" },
new Categories { Name="Amplifiers"}
};
显示的输出:
岩石
古典
爵士乐
流行迪斯科
拉丁
金属
另类雷鬼
蓝调
等等等
另外,我想在EF代码中,第一种方法是对种子数据的更改将动态地反映在所连接的数据库中(数据库连接工作正常)
请在这里需要一些指导。 提前致谢
您需要将种子数据添加到数据库上下文中:
protected override void Seed(MusicStoreEntities context)
{
context.Categries.Add(new Categories { Name = "Guitars" });
context.Categries.Add(new Categories { Name = "Keyboards" });
context.Categries.Add(new Categories { Name = "Drums" });
context.Categries.Add(new Categories { Name="Amplifiers"});
base.Seed(context);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.