[英]Which file to Initialize Database in WPF MVVM Entity Frameworks Code First
I've got about six months experience with WPF/MVVM and am trying to incorporate EF Code First in my project. 我在WPF / MVVM方面拥有大约六个月的经验,并且正在尝试将EF Code First纳入我的项目。 Two questions:
两个问题:
Is the layout in the image above the best to use? 图像上方的布局是否最适合使用? Is it better to use sub-projects or would sub-folders work just as well?
使用子项目会更好还是使用子文件夹? I'm open to suggestions.
我愿意提出建议。
Got this code to work in MainWindow.xaml.cs
: 得到此代码以在
MainWindow.xaml.cs
工作:
namespace someNamespace { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private EmployeeDBContext context = new EmployeeDBContext(); public MainWindow() { InitializeComponent(); Database.SetInitializer(new DropCreateDatabaseIfModelChanges<EmployeeDBContext>()); } private void Window_Loaded(object sender, RoutedEventArgs e) { System.Windows.Data.CollectionViewSource employeeViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("employeeViewSource"))); context.Employees.Load(); employeeViewSource.Source = context.Employees.Local; } private void Button_Search(object sender, RoutedEventArgs e) { //event handler code using (var context = new EmployeeDBContext()) { context.Employees.Add(employee); context.SaveChanges(); } } protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { base.OnClosing(e); this.context.Dispose(); } private void Button_Exit(object sender, RoutedEventArgs e) { this.Close(); } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.