Esempio n. 1
0
        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();

            }
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 private static int SelectPartTest(string connectionString)
 {
     List<Home> count;
     try
     {
         using (var ctx = new Context(connectionString))
         {
             count = ctx.Homes.AsNoTracking().Where(h => h.BuildYear < 2000).ToList();
         }
     }
     catch (OutOfMemoryException)
     {
         return 0;
     }
     return count.Count;
 }
Esempio n. 4
0
 private static int SelectJoinTest(string connectionString)
 {
     List<Home> count;
     try
     {
         using (var ctx = new Context(connectionString))
         {
             count = ctx.Homes.AsNoTracking().Where(h => h.HomeProvince.Code == 10).ToList();
         }
     }
     catch (OutOfMemoryException)
     {
         return 0;
     }
     return count.Count;
 }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
 private static int CountTest(string connectionString)
 {
     int count;
     using (var ctx = new Context(connectionString))
     {
         count = ctx.Homes.AsNoTracking().Count();
     }
     return 1;
 }