Ejemplo n.º 1
0
 private static void ViewData()
 {
     Console.WriteLine("View Data");
     using (var ctx = new EF6RecipesContext())
     {
         foreach (var person in ctx.PersonSet)
         {
             Console.WriteLine($"name: {person.FirstName}  surname: {person.LastName}  ");
         }
     }
 }
Ejemplo n.º 2
0
        private static async void AddDataAsync()
        {
            using (var ctx = new EF6RecipesContext())
            {
                if (ctx.PersonSet.Count() == 0)  //add only once - for test purpose
                {
                    var person = new Person {
                        FirstName = "Dawid", MiddleName = "-", LastName = "Stoga", PhoneNumber = "3154545"
                    };
                    ctx.PersonSet.Add(person);
                    person = new Person {
                        FirstName = "Magda", MiddleName = "Malgorzata", LastName = "Gaworska", PhoneNumber = "7145789"
                    };
                    ctx.PersonSet.Add(person);
                    person = new Person {
                        FirstName = "Jakub", MiddleName = "Dawid", LastName = "Stoga ", PhoneNumber = "brak"
                    };
                    ctx.PersonSet.Add(person);
                    int x = await ctx.SaveChangesAsync();

                    Console.WriteLine($"Added {x} rows");
                }
            }
        }