public void TestInsertUser() { using (var db = new KptBoardModel()) { // 全レコードを削除 foreach (var u in db.Users.ToArray()) { db.Remove <User>(u); } db.Add(new User { Name = "User01" }); db.Add(new User { Name = "User02", Age = 2 }); db.SaveChanges(); } }
public void TestInsertUserAndKptBoard() { using (var db = new KptBoardModel()) { var user = new User // Userが1つ、KptBoardが3つのインスタンスを作り上げる { Name = "User03", Age = 3, KptBoards = { new KptBoard { Time = DateTime.Now, Keep = "続けることだけ" }, new KptBoard { Time = DateTime.Now, Problem = "続けることだけ" }, new KptBoard { Time = DateTime.Now, Try = "試すことだけ" }, } }; db.Add(user); // 追加 db.SaveChanges(); } }