Exemplo n.º 1
0
        public string InitializeTimelinesQuickCount()
        {
            var db = new edayRoomEntities();

            db.ClearQuickCount();
            var centros      = db.Centroes.Include("Movilizadors").Include("TestigoExitPolls").Where(c => c.quickCountActive ?? false).ToList();
            var tlQuickCount = new List <QuickCountTimeline>();


            foreach (var c in centros)
            {
                if (c.quickCountActive ?? false)
                {
                    tlQuickCount.Add(new QuickCountTimeline
                    {
                        activa    = true,
                        id_centro = c.id,
                        fecha     = DateTime.Now,
                        id_parent = null
                    });
                }
            }



            using (
                var con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnSimple"].ConnectionString)
                )
            {
                con.Open();

                #region QuickCount Timeline
                using (var tran = con.BeginTransaction())
                {
                    var bc = new SqlBulkCopy(con,
                                             SqlBulkCopyOptions.CheckConstraints |
                                             SqlBulkCopyOptions.FireTriggers |
                                             SqlBulkCopyOptions.KeepNulls, tran)
                    {
                        BatchSize = 1000, DestinationTableName = "quickcountTimeline"
                    };

                    bc.WriteToServer(tlQuickCount.AsDataReader());

                    tran.Commit();
                }
                #endregion

                con.Close();
            }



            return("todo inicializado, bien");
        }