예제 #1
0
파일: Program.cs 프로젝트: vitek0585/efcore
        private static void AddPlayersThenError(UefaDbContext context)
        {
            var address = new Address {
                City = "Donetsk"
            };

            context.Players.Add(new Player
            {
                Name    = "Rakitskiy",
                Address = address
            });

            context.Players.Add(new Player
            {
                Name = "Milevskiy",
                // cannot be shared by multiple owners
                Address = address
            });

            context.Players.Add(new Player
            {
                Name = "RaHitich",
                // cannot be null
            });

            context.SaveChanges();
        }
예제 #2
0
파일: Program.cs 프로젝트: vitek0585/efcore
        static void Main(string[] args)
        {
            using (var context = new UefaDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                AddPlayers(context);
                //AddPlayersThenError(context);

                foreach (var player in context.Players)
                {
                    Console.WriteLine($"{player.Name} {player.Address?.City}");
                }
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: vitek0585/efcore
        private static void AddPlayers(UefaDbContext context)
        {
            context.Players.Add(new Player
            {
                Name    = "Rakitskiy",
                Address = new Address {
                    City = "Donetsk"
                }
            });

            context.Players.Add(new Player
            {
                Name = "Milevskiy",
                // cannot be null
                // cannot be shared by multiple owners
                Address = new Address()
            });

            context.SaveChanges();
        }