コード例 #1
0
ファイル: Program.cs プロジェクト: evertonmota/SamuraiAppCore
 //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();
 }
コード例 #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();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: evertonmota/SamuraiAppCore
        //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();
            }
        }
コード例 #5
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();
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
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();
     }
 }
コード例 #8
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();
            }
        }
コード例 #9
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();
     }
 }
コード例 #10
0
        private static void InsertSamurai1()
        {
            var samurai = new Samurai {
                Name = "Kire"
            };

            using (var context = new SamuraiDbContext())
            {
                context.Samurais.Add(samurai);
                context.SaveChanges();
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: evertonmota/SamuraiAppCore
        //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();
            }
        }
コード例 #12
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();
            }
        }
コード例 #13
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();
            }
        }
コード例 #14
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();
            }
        }
コード例 #15
0
        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();
        }
コード例 #16
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();
            }
        }
コード例 #17
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();
            }
        }
コード例 #18
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();
     }
 }
コード例 #19
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();
            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: evertonmota/SamuraiAppCore
        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();
            }
        }
コード例 #21
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();
            }
        }
コード例 #22
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();
            }
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: evertonmota/SamuraiAppCore
        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();
            }
        }
コード例 #24
0
        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();
            }
        }
コード例 #25
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();
            }
        }
コード例 #26
0
        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();
            }
        }
コード例 #27
0
        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();
            }
        }
コード例 #28
0
        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();
            }
        }
コード例 #29
0
        private static void RetrieveAndUpdateSamurai()
        {
            var samurai = _context.Samurais.FirstOrDefault();

            samurai.Name += "San";
            _context.SaveChanges();
        }
コード例 #30
0
 public int Commit()
 {
     return(context.SaveChanges());
 }