Trynig到的DataContext设置为WPF窗口我使用CodeFirst这里是代码WPF窗口的DataContext错误“无效列名”
public class Employee
{
[Key]
public int EmployeeId { get; set; }
[Display(Name = "FullName")]
[Required(ErrorMessage = "FullNameRequired")]
public string FullName { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
public double Salary { get; set; }
public string Email { get; set; }
public string Job { get; set; }
}
public class EmployeeVM
{
SDBContext db = new SDBContext();
public List<Employee> Employees;
public EmployeeVM()
{
this.Employees= db.Employees.ToList();
}
}
添加视图模型到窗口的DataContext
xmlns:VM="clr-namespace:Project_Test.ViewModels"
<Window.DataContext>
<VM:EmployeeVM/>
</Window.DataContext>
但我得到错误“无效的列名作业”
和我试图绑定'员工'收集到DataGrid,但它没有工作
ItemsSource="{Binding Employees}"
完成,在隐藏代码,它工作正常
SDBContext db = new SDBContext();
public MainWindow()
{
InitializeComponent();
DG_Employees.ItemsSource = db.Employees.ToList();
}
更新
我删除属性“工作”,并得到了另一个错误: “的模式支持背景自上改变数据库已创建。考虑使用代码第一”