Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }
Ejemplo n.º 3
0
        //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();
            }
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
 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();
     }
 }
Ejemplo n.º 6
0
        private static void LinqQuery()
        {
            using (var dbNew = new SamuraiDbContext())
            {
                var query = from s in dbNew.Samurais
                            where EF.Functions.Like(s.Name, "S%")
                            select s;

                var temp = query.ToList();
            }
        }
Ejemplo n.º 7
0
 public static void GetQuotes()
 {
     using (var db = new SamuraiDbContext())
     {
         var quotes = db.Quotes.Include(q => q.Samurai).Where(q => EF.Functions.Like(q.Text, "Q%")).ToList();
         foreach (var quote in quotes)
         {
             Console.WriteLine($"Samuri: {quote.Samurai.Name} - {quote.Text}");
         }
     }
 }
Ejemplo n.º 8
0
 public static void GetSamuraiQuote()
 {
     using (var db = new SamuraiDbContext())
     {
         var result = db.Samurais.Select(s => new { SamName = s.Name, QuotesCount = s.Quotes.Count }).ToList();
         foreach (var item in result)
         {
             Console.WriteLine($"{item.SamName} : Count: {item.QuotesCount}");
         }
     }
 }
Ejemplo n.º 9
0
        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();
            }
        }
Ejemplo n.º 10
0
        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();
            }
        }
Ejemplo n.º 11
0
 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();
     }
 }
Ejemplo n.º 12
0
        private static void InsertSamurai1()
        {
            var samurai = new Samurai {
                Name = "Kire"
            };

            using (var context = new SamuraiDbContext())
            {
                context.Samurais.Add(samurai);
                context.SaveChanges();
            }
        }
Ejemplo n.º 13
0
        //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();
            }
        }
Ejemplo n.º 14
0
 private static void RetornaTodosSamurais()
 {
     using (var context = new SamuraiDbContext())
     {
         var samurais = context.Samurais.ToList();
         var query    = context.Samurais;
         foreach (var s in samurais)
         {
             Console.WriteLine(s.Name);
         }
     }
 }
Ejemplo n.º 15
0
 private static void SimpleSamuraiQuery()
 {
     using (var context = new SamuraiDbContext())
     {
         var samurais = context.Samurais.ToList();
         //var query = context.Samurais;
         //var samuraisAgain = query.ToList();
         foreach (var samurai in context.Samurais)
         {
             Console.WriteLine(samurai.Name);
         }
     }
 }
Ejemplo n.º 16
0
        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();
            }
        }
Ejemplo n.º 17
0
        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();
            }
        }
Ejemplo n.º 18
0
 private static void MoreQueries()
 {
     using (var context = new SamuraiDbContext())
     {
         var samurais_NonParameterizedQuery = context.Samurais.Where(s => s.Name == "Sampson").ToList();
         var name = "Sampson";
         var samurais_ParameterizedQuery = context.Samurais.Where(s => s.Name == name).ToList();
         var samurai_Object = context.Samurais.FirstOrDefault(s => s.Name == name);
         var samurais_ObjectFindByKeyValue = context.Samurais.Find(2);
         var samuraisJ          = context.Samurais.Where(s => EF.Functions.Like(s.Name, "K%")).ToList();
         var search             = "K%";
         var samuraisJParameter = context.Samurais.Where(s => EF.Functions.Like(s.Name, search)).ToList();
     }
 }
Ejemplo n.º 19
0
        public static void AddQuoteDisc()
        {
            var quote = new Quote
            {
                Text      = "Quote 4",
                SamuraiId = 11
            };

            using (var db = new SamuraiDbContext())
            {
                db.Quotes.Add(quote);
                db.SaveChanges();
            }
        }
Ejemplo n.º 20
0
        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();
            }
        }
Ejemplo n.º 21
0
 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();
     }
 }
Ejemplo n.º 22
0
        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();
            }
        }
Ejemplo n.º 23
0
        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();
            }
        }
Ejemplo n.º 24
0
 public static void GetSamuraiWithQuotes()
 {
     using (var db = new SamuraiDbContext())
     {
         var samurais = db.Samurais.Include(s => s.Quotes).Where(s => EF.Functions.Like(s.Name, "K%")).ToList();
         foreach (var samurai in samurais)
         {
             Console.WriteLine($"{samurai.Id} {samurai.Name}");
             Console.WriteLine("--------------------------------------");
             foreach (var quote in samurai.Quotes)
             {
                 Console.WriteLine($"{quote.Id} {quote.Text} {quote.SamuraiId}");
             }
         }
     }
 }
Ejemplo n.º 25
0
        public static void QuerySamurai()
        {
            using (var db = new SamuraiDbContext())
            {
                var temp     = "Kire";
                var samurais = db.Samurais.Where(s => s.Name == temp).ToList();
                foreach (var samurai in samurais)
                {
                    Console.WriteLine($"{samurai.Id} {samurai.Name}");
                }

                //var samurai = samurais.Where(s => s.Id == 1).Single();
                var sam = samurais.SingleOrDefault(s => s.Id == 1);
                Console.WriteLine($"Samurai: {sam.Id} {sam.Name}");
            }
        }
Ejemplo n.º 26
0
        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();
            }
        }
Ejemplo n.º 27
0
        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();
            }
        }
Ejemplo n.º 28
0
        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();
            }
        }
Ejemplo n.º 29
0
        //Додадете на битката со 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();
            }
        }
Ejemplo n.º 30
0
        //Додаете нова битка во која учествувал самурајот со 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();
            }
        }