Beispiel #1
0
        private static void QueryAndUpdateBattle_Disconnected()
        {
            var battle = _context.Battles.AsNoTracking().FirstOrDefault();

            battle.EndDate = new DateTime(1560, 06, 30);
            using (var newContextInstance = new samuraiContext())
            {
                newContextInstance.Battles.Update(battle);
                newContextInstance.SaveChanges();
            }
        }
Beispiel #2
0
        private static void AddQuoteToExistingSamuraiNotTracked(int samuraiId)
        {
            var samurai = _context.samurais.Find(samuraiId);

            samurai.Quotes.Add(new Quote
            {
                Text = "Now that I saved you , will you feed me dinner?"
            });
            using (var newContext = new samuraiContext())
            {
                newContext.samurais.Update(samurai);
                newContext.SaveChanges();
            }
        }
Beispiel #3
0
        private static void AddQuoteToExistingSamuraiNotTracked_Easy(int samuraiId)
        {
            var quote = new Quote
            {
                Text      = "Now that I saved you, will you feed me dinner again?",
                SamuraiId = samuraiId
            };

            using (var newContext = new samuraiContext())
            {
                newContext.Quotes.Add(quote);
                newContext.SaveChanges();
            }
        }
Beispiel #4
0
 public void CanInsertSamuraiIntoDatabase()
 {
     using (var context = new samuraiContext())
     {
         //context.Database.EnsureDeleted();
         context.Database.EnsureCreated();
         var samurai = new samurai();
         context.samurais.Add(samurai);
         Debug.WriteLine($"Before save: {samurai.Id}");
         context.SaveChanges();
         Debug.WriteLine($"After save: {samurai.Id}");
         Assert.AreNotEqual(0, samurai.Id);
     }
 }