public StudentRepository(MyDbContext ctx) { this._ctx = ContainerManager.Current.Resolve <MyDbContext>(); }
public Form1() { InitializeComponent(); initializeDateTimePicker(); dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToDeleteRows = false; buttonAdd.Click += buttonAdd_Click; buttonDelete.Click += buttonDelete_Click; buttonEdit.Click += buttonEdit_Click; using (MyDbContext context = new MyDbContext()) { context.Database.EnsureCreated(); } using (MyDbContext context = new MyDbContext()) { context.Database.EnsureCreated(); MyData data = context.Find <MyData>(1u); if (null != data) { Console.WriteLine("Found"); Console.WriteLine(data.Name); } else { Console.WriteLine("Not Found"); } BindingSource bi = new BindingSource(); bi.DataSource = context.Find <MyData>(1u); dataGridView1.DataSource = bi; dataGridView1.Refresh(); } using (MyDbContext context = new MyDbContext()) { context.Database.EnsureCreated(); MyData found = null; foreach (var item in from data in context.Data where data.Key == 1 select data) { found = item; break; } if (null == found) { return; } //found.Number++; context.SaveChanges(); } using (MyDbContext context = new MyDbContext()) { context.Add(new MyData() { Name = "이름", Number = 123 }); context.SaveChanges(); } }