Exemple #1
0
        public string InitializeTimelinesTotalizacion()
        {
            var db = new edayRoomEntities();

            db.ClearTotalizacion();
            var mesas   = db.Mesas.Include("Testigoes").ToList();
            var centros = db.Centroes.Include("Movilizadors").Include("TestigoExitPolls").ToList();

            var tlTotalizacion = new List <TotalizacionTimeline>();

            foreach (var m in mesas)
            {
                tlTotalizacion.Add(new TotalizacionTimeline
                {
                    activa  = true,
                    id_mesa = m.id,
                    fecha   = DateTime.Now
                });
            }

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

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

                    bc.WriteToServer(tlTotalizacion.AsDataReader());

                    tran.Commit();
                }
                #endregion

                con.Close();
            }



            return("todo inicializado, bien");
        }