コード例 #1
0
        public static Int32 LoadCSV <EntType>(String[][] campos, IEnumerable <TSEMapper> map, String path)
        {
            GC.Collect();

            DateTime inicio = DateTime.Now;

            TSEdbContext DB = new TSEdbContext();

            {
                int i = 0;
                foreach (String[] cmps in campos)
                {
                    try
                    {
                        String  jsonString = JsonObject(cmps, map);
                        EntType entity     = JsonSerializer.Deserialize <EntType>(jsonString);
                        DB.Set(entity.GetType()).Add(entity);
                        if (++i % 100 == 0)
                        {
                            //Console.Write(".");
                            try
                            {
                                DB.SaveChanges();
                                DB.Dispose();
                                DB = new TSEdbContext();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Deu merda: {0}", ex.Message);
                                Console.ReadLine();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Deu merda: {0}", ex.Message);
                        Console.ReadLine();
                    }
                }

                try
                {
                    DB.SaveChanges();
                    DB.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Deu merda: {0}", ex.Message);
                    Console.ReadLine();
                }

                DateTime fim       = DateTime.Now;
                TimeSpan intervalo = fim - inicio;
                Console.Write("Tempo:  {0} ", intervalo.ToString());
            }

            return(campos.Length);
        }
コード例 #2
0
        public static void SumValores <CnddtrType, BensType>()
        {
            GC.Collect();

            TSEdbContext DB = new TSEdbContext();
            {
                IQueryable <Candidatura>  cnddtrs = (IQueryable <Candidatura>)DB.Set(typeof(CnddtrType));
                IQueryable <BemCandidato> bens    = (IQueryable <BemCandidato>)DB.Set(typeof(BensType));

                var valores = (from bem in bens
                               group bem by bem.BemSeqCand into bensCand
                               select new
                {
                    Cand = bensCand.Key,
                    Bens = bensCand.Sum(b => b.BemCandValor)
                }).ToList();

                int i = 0;
                foreach (var valor in valores)
                {
                    Candidatura cnddtr = cnddtrs.First(c => c.SeqCand.Equals(valor.Cand));
                    cnddtr.TotBensValor = valor.Bens;
                    if (++i % 100 == 0)
                    {
                        try
                        {
                            Console.Write(".");
                            DB.SaveChanges();
                            DB.Dispose();
                            DB      = new TSEdbContext();
                            cnddtrs = (IQueryable <Candidatura>)DB.Set(typeof(CnddtrType));
                            bens    = (IQueryable <BemCandidato>)DB.Set(typeof(BensType));
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Deu merda: {0}", ex.Message);
                            Console.ReadLine();
                        }
                    }
                }

                try
                {
                    Console.WriteLine();
                    DB.SaveChanges();
                    DB.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }