コード例 #1
0
ファイル: Program.cs プロジェクト: samuraoka/SamuraiAppCore
        public static async Task AddManyToManyWithFksAsync()
        {
            // Add samurai and battles for subsequence processing
            await InsertNewPkFkGraphAsync();
            await AddBattlesAsync();

            // Best way to check if object exists in Entity Framework?
            // https://stackoverflow.com/questions/1802286/best-way-to-check-if-object-exists-in-entity-framework
            var samurai = await Context.Samurais.FirstOrDefaultAsync();

            var battle = await Context.Battles.FirstOrDefaultAsync();

            if (samurai != null && battle != null)
            {
                var sb = new SamuraiBattle {
                    SamuraiId = samurai.Id, BattleId = battle.Id
                };
                var existanceOfSamuraiBattle = await Context.SamuraiBattles.AnyAsync(
                    x => (x.SamuraiId == samurai.Id && x.BattleId == battle.Id));

                if (existanceOfSamuraiBattle == false)
                {
                    await Context.SamuraiBattles.AddAsync(sb);

                    await Context.SaveChangesAsync();
                }
            }
        }
コード例 #2
0
        private static void InsertSamuraiWithBattle()
        {
            var samurai = new Samurai
            {
                Name = "Pepe de la batalla"
            };

            var battle = new Battle
            {
                Name      = "Super battle",
                StartDate = new DateTime(1575, 1, 1),
                EndDate   = new DateTime(1575, 2, 2)
            };

            _context.AddRange(samurai, battle);

            var samuraiBattle = new SamuraiBattle
            {
                SamuraiId = samurai.Id,
                BattleId  = battle.Id
            };

            _context.Add(samuraiBattle);

            _context.SaveChanges();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: markopedu/ImagesWebApi
        private static List <SamuraiBattle> createSamuraiBattles(int index, Samurai samurai)
        {
            var even           = index % 2 == 0;
            var fifth          = index % 5 == 0;
            var samuraiBattles = new List <SamuraiBattle>();
            var num            = 1;

            if (even)
            {
                num = 2;
            }
            else if (fifth)
            {
                num = 5;
            }

            for (var i = 0; i < num; i++)
            {
                var b  = createBattle();
                var sb = new SamuraiBattle
                {
                    Battle  = b,
                    Samurai = samurai
                };

                samuraiBattles.Add(sb);
            }

            return(samuraiBattles);
        }
コード例 #4
0
        internal void AddSuperSamuraisIntoDatabase()
        {
            var sb = new SamuraiBattle {
                Battle = new Battle {
                    Name = "Krig 1", Description = "Det var ett hårt krig", Brutal = true, Start = new DateTime(2001, 05, 22), End = new DateTime(2006, 05, 22), BattleLog = new BattleLog {
                        Name = "Krigslogg 1", BattleEvents = new List <BattleEvent> {
                            new BattleEvent {
                                Name = "Kriget om vem som var bäst samsung/apple", Description = "folk bråkar"
                            }
                        }
                    }
                }, Samurai = new Samurai {
                    Name = "Lugi", Age = 12, Email = "*****@*****.**", HairCuts = new HairCut {
                        Name = "ShortHair"
                    }, SecretIdentity = new SecretIdentity {
                        RealName = "Klas-Göran"
                    }, Quotes = new List <Quote> {
                        new Quote {
                            Name = "Livet är gött", PhilosophiLVL = 100, QuoteType = new QuoteType {
                                Name = "SuperQuote!"
                            }
                        }
                    }
                }
            };

            context.Add(sb);
            context.SaveChanges();
        }
コード例 #5
0
        private static void RemoveJoin()
        {
            var join = new SamuraiBattle {
                BatlleId = 1, SamuraiId = 2
            };

            _context.Remove(join);
            _context.SaveChanges();
        }
コード例 #6
0
        private static void JoinBattleAndSamurai()
        {
            var sbJoin = new SamuraiBattle {
                SamuraiId = 1, BattleId = 3
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: bajanf/ORM.EF.Core3.1App
        private static void RemoveJoinBetweenSamuraiAndBattleSimple()
        {
            var join = new SamuraiBattle {
                BattleId = 1, SamuraiId = 11
            };

            _context.Remove(join);
            _context.SaveChanges();
        }
コード例 #8
0
        private static void AddManyToManyWithFks()
        {
            var sb = new SamuraiBattle {
                SamuraiId = 1, BattleId = 1
            };                                                        // Only need the two main Ids.

            _context.SamuraiBattles.Add(sb);
            _context.SaveChanges();
        }
コード例 #9
0
        private static void RemoveJoinBattleSamurai()
        {
            var join = new SamuraiBattle {
                BattleId = 1, SamuraiId = 3
            };

            _ctx.Remove(join);
            _ctx.SaveChanges();
        }
コード例 #10
0
        private static void AddManyToManyWithFks()
        {
            var sb = new SamuraiBattle {
                SamuraiId = 23, BattleId = 2
            };

            _context.SamuraiBattles.Add(sb);
            _context.SaveChanges();
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: bajanf/ORM.EF.Core3.1App
        public static void JoinBattleAndSamurai()
        {
            var sbJoin = new SamuraiBattle {
                BattleId = 3, SamuraiId = 11
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #12
0
        private static void JoinBattleAndSamurai()
        {
            var sbJoin = new SamuraiBattle {
                BattleId = 3, SamuraiId = 8
            };

            Context.Add(sbJoin);
            Context.SaveChanges();
        }
コード例 #13
0
        private static void JoinBattleAndSamurai()
        {
            var join = new SamuraiBattle {
                SamuraiId = 3, BattleId = 1
            };

            _ctx.Add(join);
            _ctx.SaveChanges();
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: Jmach83/SamuraiApp
        private static void JoinBattleAndSamurai()
        {
            //Kikuchiyo is is 42, Siege of Osaka id is 5
            var sbJoin = new SamuraiBattle {
                SamuraiId = 42, BattleId = 5
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #15
0
        private static void JoinBattleAndSamurai()
        {
            // Samurai and battle already exist and we have their Ids
            var sbJoin = new SamuraiBattle {
                BattleId = 1, SamuraiId = 9
            };

            context.Add(sbJoin);
            context.SaveChanges();
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: MiloszBoghePXL/School-Y3-
        private static void JoinBattleAndSamurai()
        {
            //Samurai and Battle already exist and we have their IDs
            var sbJoin = new SamuraiBattle {
                SamuraiId = 2, BattleId = 1
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #17
0
        private static void RemoveJoinBetweenSamuraiAndBattle()
        {
            //Normalnie powinniśmy najpierw pobrać obiekt, ale tu jest tak prosto, że jest bezpiecznie go utworzyć
            var join = new SamuraiBattle {
                BattleId = 1, SamuraiId = 1
            };

            _context.Remove(join);
            _context.SaveChanges();
        }
コード例 #18
0
        private static async Task JoinBattleAndSamuraiAsync()
        {
            var sbJoin = new SamuraiBattle {
                SamuraiId = 2, BattleId = 1
            };
            //There is no DbSet SamuraiBattle. We cannot use context.SamuraiBattles.Add
            await context.AddAsync(sbJoin);

            await context.SaveChangesAsync();
        }
コード例 #19
0
        public IActionResult Privacy()
        {
            var sbJoin = new SamuraiBattle {
                SamuraiId = 1, BattleId = 3
            };

            samuraiContext.Add(sbJoin);
            samuraiContext.SaveChanges();
            return(View());
        }
コード例 #20
0
        private static void AddManyToMayWithFks()
        {
            _context = new SamuraiContext();
            var sb = new SamuraiBattle {
                SamuraiId = 1, BattleId = 1
            };

            _context.SamuraiBattles.Add(sb);
            _context.SaveChanges();
        }
コード例 #21
0
        private static async Task RemoveJoinBattleAndSamuraiAsync()
        {
            //It is recommended to retrieve table from DB and delete it. For simple tables like SamuraiBattle the following approach is acceptable
            var sbJoin = new SamuraiBattle {
                SamuraiId = 2, BattleId = 1
            };

            context.Remove(sbJoin);
            await context.SaveChangesAsync();
        }
コード例 #22
0
        private static void RemoveJoinBetweenSamuraiAndBattleSimple()
        {
            var join = new SamuraiBattle {
                BattleId = 1, SamuraiId = 11
            };

            // Begin tracking and set state as deleted (only the delete call is performed on the database).
            context.Remove(join);
            context.SaveChanges();
        }
コード例 #23
0
        private static void JoinBattleAndSamurai()
        {
            //Samurai i bitwa już istnieją i mamy ich IDs
            var sbJoin = new SamuraiBattle {
                SamuraiId = 1, BattleId = 3
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #24
0
        private static void JoinBattleAndSamurai()
        {
            //Kikuchiyo id is 1, Siege of Osaka id is 3
            var sbJoin = new SamuraiBattle {
                SamuraiId = 1, BattleId = 3
            };

            Context.Add(sbJoin);
            Context.SaveChanges();
        }
コード例 #25
0
        // Add already created samurai and battle
        private static void JoinBattleAndSamurai()
        {
            // Kikuchiyo id is 8, Siege of Osaka is 7
            var sbJoin = new SamuraiBattle {
                SamuraiId = 8, BattleId = 7
            };

            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #26
0
 private static void JoinBattleAndSamurai()
 {
     using (var context = new BusinessDBContext())
     {
         var sbJoin = new SamuraiBattle {
             SamuraiId = 1, BattleId = 3
         };
         context.Add(sbJoin);
         context.SaveChanges();
     }
 }
コード例 #27
0
        private static void JoinBattleAndSamurai()
        {
            var samuraiBattle = new SamuraiBattle
            {
                SamuraiId = 1,
                BattleId  = 1
            };

            Context.Add(samuraiBattle);
            Context.SaveChanges();
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: gbarska/entity-mappings
        private static void JoinBattleAndSamurai()
        {
            var sbJoin = new SamuraiBattle {
                SamuraiId = 1, BattleId = 3
            };

            //as SamuraiBattle is a join entity we don't have a Dbset and in this case
            //the context itself handles the query
            _context.Add(sbJoin);
            _context.SaveChanges();
        }
コード例 #29
0
        private static void JoinBattleAndSamurai()
        {
            // Samurai and Battle already exist and we have their id's.
            var sbJoin = new SamuraiBattle {
                SamuraiId = 11, BattleId = 1
            };

            // Note, there is no DbSet for the SamuraiBattle class.
            context.Add(sbJoin);
            context.SaveChanges();
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: restin84/SamuraiApp
        private static void RemoveJoinBetweenSamuraiAndBattleSimple()
        {
            var join = new SamuraiBattle {
                BattleId = 1, SamuraiId = 2
            };

            //here we are just instructing EF Core to delete the SamuraiBattle
            //where BattleId = 1 and SamuraiId = 2
            context.Remove(join);
            context.SaveChanges();
        }