public void InitDataBase(string connectionString) { using (var ctx = new Context(connectionString)) { if (ctx.Database.Exists()) ctx.Database.Delete(); ctx.Database.Initialize(true); List<Province> entityProwinces = new List<Province>(); foreach (var province in ProvinceData.GetProvinces()) { var prow = new Province { Code = province.Code, Name = province.Name }; ctx.Provinces.Add(prow); ctx.SaveChanges(); entityProwinces.Add(prow); } BulkUploadToSql bulk = BulkUploadToSql.Load( HomeData.GetHomes() .Select( i => new Bulk.Home { AddTime = DateTime.Now, BuildYear = i.BuildYear, City = i.City, Description = i.Description, Price = i.Price, Surface = i.Surface, ProvinceId = entityProwinces.Single(j => j.Code == i.HomeProvince.Code).Id }), "Home", 10000, connectionString); bulk.Flush(); } }
private static int Update100Test(string connectionString) { int count; using (var ctx = new Context(connectionString)) { var homes = ctx.Homes.Where(h => h.BuildYear == 2014); count = homes.Count(); foreach (var home in homes) { if (home != null) { home.BuildYear = 2015; } } ctx.SaveChanges(); } return count; }
private static int InsertTest(string connectionStrning) { using (var ctx = new Context(connectionStrning)) { var entityProwinces = ctx.Provinces.ToList(); foreach (var home in HomeData.Get100Homes()) { ctx.Homes.Add(new Home { BuildYear = home.BuildYear, City = home.City, Description = home.Description, HomeProvince = entityProwinces.Find(i => i.Code == home.HomeProvince.Code), Price = (decimal)home.Price, Surface = home.Surface, AddTime = DateTime.Now }); ctx.SaveChanges(); } } return 100; }