public void SaveTest() { using (DbConnection connection = GetConnection()) using (CarsContext context = new CarsContext(connection)) { context.Cars.Add(new Car { Name = "Maserati" }); context.Cars.Add(new Car { Name = "Ferrari" }); context.Cars.Add(new Car { Name = "Lamborghini" }); context.SaveChanges(); } }
public static void SeedPersons(CarsContext context) { if (context.Persons.Count() != 0) { return; } for (int i = 0; i < 10; i++) { context.Persons.Add(new Person() { Name = "PersonName " + (10 - i) } ); } context.SaveChanges(); }
public void SkipTakeTest() { using (DbConnection connection = GetConnection()) using (CarsContext context = new CarsContext(connection)) { Seed.SeedPersons(context); List <Person> persons = context.Persons.OrderBy(p => p.Name).Skip(3).Take(5).ToList(); Assert.AreEqual(5, persons.Count); foreach (Person person in persons) { Console.WriteLine(person.Name); } Console.WriteLine("====================="); foreach (Person person in context.Persons.OrderBy(p => p.Name).ToList()) { Console.WriteLine(person.Name); } } }