我不能播种“IsTerminated”

时间:2017-02-03 18:26:00

标签: entity conditional-statements seed

为什么“IsTerminated”数据没有在数据库中设置? 其他一切都很好。

没有这个条件正常工作。

 map.Requires("IsTerminated").HasValue(false)                                
                        }).Ignore(m => m.IsTerminated)"

条件元素

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Employee>()
                    .Map(map =>
                        {
                            map.Properties(p => new
                                {
                                    p.Id,
                                    p.Name,
                                    p.Salary,
                                    //p.IsTerminated,
                                    p.DepartmentId
                                });
                            map.Requires("IsTerminated").HasValue(false);
                            map.ToTable("tblEmployees");
                        }).Ignore(m => m.IsTerminated)
                    .Map(map =>
                            {
                                map.Properties(p => new
                                    {
                                        p.Id,
                                        p.Email,
                                        p.Mobile
                                    });
                                map.ToTable("EmployeeContactDetails");
                            });

        base.OnModelCreating(modelBuilder);
    }

种子方法

 protected override void Seed(EmployeeDBContext context)
    {
    Department department1 = new Department()
            {
                Name = "Sales",
                Employees = new List<Employee>()
                    {
                        new Employee()
                            {                                    
                                Name = "Mantas",
                                Salary = 60000,
                                Email = "Mantas@gmail.com",
                                Mobile = "+37061433005",
                                IsTerminated = true
                            },
                        new Employee()
                            {
                                Name = "Gediminas",
                                Salary = 40000,
                                Email = "Gediminas@gmail.com",
                                Mobile = "+37061433004",
                                IsTerminated = false
                            }
                    }
            };

        context.Departments.Add(department1);
        base.Seed(context);
        }

看起来这不是大问题,但我无法弄清楚为什么在我为代码添加一些条件时种子停止工作。

0 个答案:

没有答案