如题:
我的测试项目升级到EF4.1 RC 后 seed()方法里面的数据无法写入到 数据库中。大师们有没有类似的问题啊:
DBInitializer代码----:
1 public class DBInitializer : DropCreateDatabaseIfModelChanges<ConferenceMSEntitiesContext>
2 {
3 protected override void Seed(ConferenceMSEntitiesContext context)
4 {
5 var de = new List<Department> {
6 new Department{
7 Name="小庙",
8 DepartmentTypeID=1
9 },
10 new Department{
11 Name="经济局",
12 DepartmentTypeID=3
13 },
14
15 new Department{
16 Name="发改局",
17 DepartmentTypeID=3,
18
19 }
20
21 };
22
23
24
25 de.ForEach(d => context.Departments.Add(d));
26
27
28
29
30
31
32 }
33
34 }
35 }
以上代码最后不论是否添加 base.Seed(context); 和 context.SaveChanges(); 这两行代码,都无法把数据写进数据库。
Application_Start-----------------
1 protected void Application_Start()
2 {
3
4 System.Data.Entity.Database.SetInitializer<ConferenceMSEntitiesContext>(new DBInitializer());
5
6 AreaRegistration.RegisterAllAreas();
7
8 RegisterGlobalFilters(GlobalFilters.Filters);
9 RegisterRoutes(RouteTable.Routes);
10 }