示例#1
0
        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
        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
        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();
        }