//Insert Battles private static void InsertBattle() { _context.Battles.Add(new Battle { Name = "Battle of Ozzy", StartDate = new DateTime(1979, 01, 01), EndDate = new DateTime(1980, 01, 31) }); _context.SaveChanges(); }
private static void SamuraiWithQoutes() { var samurai = new Samurai(); samurai.Quotes.Add(new Quote { Text = "Qoute1" }); samurai.Quotes.Add(new Quote { Text = "Qoute2" }); samurai.Quotes.Add(new Quote { Text = "Qoute3" }); samurai.Name = "Andrej"; samurai.SecretIdentity = new SecretIdentity { RealName = "Jacki" }; using (var db = new SamuraiDbContext()) { db.Samurais.Add(samurai); db.SaveChanges(); } }
private static void UpdateBattle1SamuraiDiscScen() { Battle b; using (var db = new SamuraiDbContext()) { b = db.Battles.Single(b => b.Id == 3); } var samuraiBattles = new List <SamuraiBattle> { new SamuraiBattle { SamuraiId = 7, BattleId = 3 }, new SamuraiBattle { SamuraiId = 14, BattleId = 3 } }; using (var db2 = new SamuraiDbContext()) { db2.SamuraiBattle.AddRange(samuraiBattles); db2.SaveChanges(); } }
//delete private static void DeleteWhileNotTracked() { var samurai = _context.Samurais.FirstOrDefault(s => s.Name == "Everton Mota"); using (var ContextApp = new SamuraiDbContext()) { ContextApp.Samurais.Remove(samurai); ContextApp.SaveChanges(); } }
private static void QueryAndUpdateSamurai_Disconnected() { var samurai = _context.Samurais.FirstOrDefault(s => s.Name == "Kikuchiyo"); samurai.Name += "San"; using (var newContextInstance = new SamuraiDbContext()) { newContextInstance.Samurais.Update(samurai); newContextInstance.SaveChanges(); } }
private static void DeleteWhileNotTracked() { var samurai = _context.Samurais.FirstOrDefault(s => s.Name == "Heihachi Hayashida"); using (var contextNewAppInstance = new SamuraiDbContext()) { contextNewAppInstance.Samurais.Remove(samurai); //contextNewAppInstance.Entry(samurai).State=EntityState.Deleted; contextNewAppInstance.SaveChanges(); } }
public static void AddQuote() { using (var db = new SamuraiDbContext()) { var s = db.Samurais.Single(x => x.Id == 11); s.Quotes.Add(new Quote { Text = "Quote 3" }); db.SaveChanges(); } }
private static void QueryAndUpdateBattle_Disconnected() { var battle = _context.Battles.FirstOrDefault(); battle.EndDate = new DateTime(1560, 06, 30); using (var newContextInstance = new SamuraiDbContext()) { newContextInstance.Battles.Update(battle); newContextInstance.SaveChanges(); } }
private static void UpdateMultipleSamurai() { using (var db = new SamuraiDbContext()) { var samurais = db.Samurais.Where(s => EF.Functions.Like(s.Name, "S%")).ToList(); foreach (var item in samurais) { item.Name = "sen" + item.Name; } db.SaveChanges(); } }
private static void InsertSamurai1() { var samurai = new Samurai { Name = "Kire" }; using (var context = new SamuraiDbContext()) { context.Samurais.Add(samurai); context.SaveChanges(); } }
//update Battles public static void UpdateQueryBattle_Disconnected() { var obj = _context.Battles.FirstOrDefault(); obj.EndDate = new DateTime(2000, 01, 01); using (var NewContext = new SamuraiDbContext()) { NewContext.Battles.Update(obj); NewContext.SaveChanges(); } }
public static void AddQuoteDisc() { var quote = new Quote { Text = "Quote 4", SamuraiId = 11 }; using (var db = new SamuraiDbContext()) { db.Quotes.Add(quote); db.SaveChanges(); } }
private static void AddChildToExistingObjectWhileNotTracked(int samuraiId) { var quote = new Quote { Text = "Now that I saved you, will you feed me dinner?", SamuraiId = samuraiId }; using (var newContext = new SamuraiDbContext()) { newContext.Quotes.Add(quote); newContext.SaveChanges(); } }
private static void UpdateDisconectedEntity() { var samurai = _context.Samurais.Include(s => s.Quotes).Single(s => s.Id == 14); var quote = samurai.Quotes.First(); quote.Text += " New One"; using (var dbNew = new SamuraiDbContext()) { dbNew.Entry(quote).State = EntityState.Deleted; dbNew.SaveChanges(); } }
public static void Initialize(SamuraiDbContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Samurais.Any()) { return; // DB has been seeded } var samurais = new Samurai[] { new Samurai() { Age = "44", Killing = 32, Name = "Moshe", SecretIdentity = new SecretIdentity { RealName = "Rubin" } }, new Samurai() { Age = "21", Killing = 32, Name = "Omer", SecretIdentity = new SecretIdentity { RealName = "Dison" } }, new Samurai() { Age = "54", Killing = 32, Name = "Ruti", SecretIdentity = new SecretIdentity { RealName = "Blue" } } }; context.Samurais.AddRange(samurais); context.SaveChanges(); context.SaveChanges(); }
private static void InsertMultipleSamurais() { var samurai = new Samurai { Name = "Kire" }; var samuraiSammy = new Samurai { Name = "Sampson" }; using (var context = new SamuraiDbContext()) { context.Samurais.AddRange(samurai, samuraiSammy); context.SaveChanges(); } }
private static void DeleteSamurai() { Samurai s; using (var db = new SamuraiDbContext()) { s = db.Samurais.First(s => EF.Functions.Like(s.Name, "S%")); } using (var dbNew = new SamuraiDbContext()) { dbNew.Samurais.Remove(s); dbNew.SaveChanges(); } }
private static void UpdateSamurai() { using (var db = new SamuraiDbContext()) { db.Samurais.Add(new Samurai { Name = "Temp" }); var s1 = db.Samurais.SingleOrDefault(s => s.Id == 1); if (s1 != null) { s1.Name = "sen" + s1.Name; } db.SaveChanges(); } }
private static void UpdateDisconectedObj() { Samurai s; using (var db = new SamuraiDbContext()) { s = db.Samurais.Single(s => s.Id == 4); } s.Name = "Dis" + s.Name; using (var dbNew = new SamuraiDbContext()) { dbNew.Samurais.Update(s); dbNew.SaveChanges(); } }
private static void InsertSamurais() { var samurai = new Samurai { Name = "Everton mota" }; var samuraiM = new Samurai { Name = "Mr Samurai" }; using (var context = new SamuraiDbContext()) { context.Samurais.AddRange(samurai, samuraiM); context.SaveChanges(); } }
public static void InsertSamurai() { var samurai = new Samurai(); samurai.Name = "Kire"; var sam2 = new Samurai(); sam2.Name = "Petar"; using (var db = new SamuraiDbContext()) { db.Samurais.Add(samurai); db.Add(sam2); db.SaveChanges(); } }
//Додадете на битката со id = 1 самураите со Id = 2 и Id = 10(со object tracking и discontinued scenario) private static void UpdateBattle1SamuraiObjTrc() { using (var db = new SamuraiDbContext()) { Battle b = db.Battles.Single(b => b.Id == 1); b.SamuraiBattles = new List <SamuraiBattle> { new SamuraiBattle { SamuraiId = 14 }, new SamuraiBattle { SamuraiId = 7 } }; db.SaveChanges(); } }
private static void InsertMultipleSamurais() { var samurai = new Samurai { Name = "MR. M" }; var battle = new Battle { Name = "Senhor dos Aneis", StartDate = new DateTime(1800, 05, 25), EndDate = new DateTime(1900, 05, 01) }; using (var context = new SamuraiDbContext()) { context.AddRange(samurai, battle); context.SaveChanges(); } }
public static void InsertDiffObj() { var sam = new Samurai { Name = "Name1" }; var bat = new Battle { Name = "Belasica", StartDate = DateTime.Today.AddDays(-30), EndDate = DateTime.Today }; using (var db = new SamuraiDbContext()) { db.AddRange(sam, bat); db.SaveChanges(); } }
//Додаете нова битка во која учествувал самурајот со Id = 11 i еден нов самурај кој има Quote и SecretIdentity а и учествувал во битката со id = 1 private static void InsertBattleSamurai11() { var battle = new Battle { Name = "battle1" }; battle.SamuraiBattles = new List <SamuraiBattle> { new SamuraiBattle { SamuraiId = 11 } }; var samurai = new Samurai { Name = "Tayfun", Quotes = new List <Quote> { new Quote { Text = "hello" } }, SecretIdentity = new SecretIdentity { RealName = "samTayfun" } }; samurai.Battles = new List <SamuraiBattle> { new SamuraiBattle { BattleId = 1 } }; battle.SamuraiBattles.Add(new SamuraiBattle { Samurai = samurai }); using (var db = new SamuraiDbContext()) { db.Battles.Add(battle); db.SaveChanges(); } }
public static void SaveComplexSamurai() { var s = new Samurai(); s.Name = "Kire"; s.Quotes.Add(new Quote { Text = "Quote 1" }); s.Quotes.Add(new Quote { Text = "Quote 2" }); using (var db = new SamuraiDbContext()) { db.Samurais.Add(s); db.SaveChanges(); } }
private static void InsertMultipleSamuraisViaBatch() { var samurai1 = new Samurai { Name = "Samurai1" }; var samurai2 = new Samurai { Name = "Samurai2" }; var samurai3 = new Samurai { Name = "Samurai3" }; var samurai4 = new Samurai { Name = "Samurai4" }; using (var context = new SamuraiDbContext()) { context.Samurais.AddRange(samurai1, samurai2, samurai3, samurai4); context.SaveChanges(); } }
public static void InsertMultipleSamurai() { var list = new List <Samurai>(); var samurai = new Samurai(); samurai.Name = "Kire"; var sam2 = new Samurai(); sam2.Name = "Petar"; list.Add(samurai); list.Add(sam2); using (var db = new SamuraiDbContext()) { db.Samurais.AddRange(samurai, sam2); db.Samurais.AddRange(list); db.AddRange(samurai, sam2); db.SaveChanges(); } }
private static void RetrieveAndUpdateSamurai() { var samurai = _context.Samurais.FirstOrDefault(); samurai.Name += "San"; _context.SaveChanges(); }
public int Commit() { return(context.SaveChanges()); }