问题描述
我创建了一个可以管理员工的网站。这些员工可以属于一个组,您应该可以在其中添加新员工,或者如果需要,可以删除一个。 这是我的网上论坛标签的图片:
您会看到“雇员”选项卡为空。 这是我的Employees.cs:
public class Employee
{
public int Id { get; set; }
[required]
[MaxLength(50,ErrorMessage = "Name cannot exceed 50 characters")]
public string Name { get; set; }
[required]
[RegularExpression(@"^[a-zA-Z0-9_0+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$",ErrorMessage = "Invalid Email Format")]
[display(Name = "Office Email")]
public string Email { get; set; }
public int DepartmentId { get; set; }
public Department Department { get; set; }
public int GroupId { get; set; }
public Group.Group Group { get; set; }
}
这是我的Group.cs:
public class Group
{
[Key]
public int GroupId { get; set; }
[required]
public string Name { get; set; }
[required]
public string Task { get; set; }
[required]
public List<Employee> Employees { get; set; }
}
最后是我的AppDbContext:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Employee>()
.HasData(
new Employee() { Id = -99,Name = "Mary",Email = "mary@gmail.com",DepartmentId = -99,GroupId = -1 },new Employee() { Id = -98,Name = "Stan",Email = "stan@gmail.com",new Employee() { Id = -97,Name = "Mike",Email = "mike@gmail.com",GroupId = -1 });
modelBuilder.Entity<Department>()
.HasData(
new Department() { DepartmentId = -99,Field = "IT",Name = "Programming Department" },new Department() { DepartmentId = -98,Field = "HR",Name = "Human Resorcues" },new Department() { DepartmentId = -97,Field = "AD",Name = "Advertisement Department" });
modelBuilder.Entity<Group.Group>()
.HasData(
new Group.Group() { GroupId = -1,Name = "Cleaner",Task = "Clean the building" }
);
modelBuilder.Entity<Problem>()
.HasData(
new Problem() { ProblemId = -99,Title = "Spilled drink in basement",Descrpition = "Someone spilled drink all over the place in the basement",IsDone= false },new Problem() { ProblemId = -98,Title = "Power problems",Descrpition = "Power goes off sometimes in the buildin",IsDone = false },new Problem() { ProblemId = -97,Title = "Internet problems",Descrpition = "Internet is very weak and some devices lose signal",IsDone = false });
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)