Beispiel #1
0
 public UserRepository(EFContextSQL context)
 {
     _context = context;
 }
Beispiel #2
0
 public AddressRepository(EFContextSQL context)
 {
     _context = context;
 }
Beispiel #3
0
 public RepositoryUser(EFContextSQL context)
 {
     _context = context;
 }
Beispiel #4
0
        private static void SeedFromSQL()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();

            Console.WriteLine("");

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var optionsBuilder = new DbContextOptionsBuilder <EFContextSQL>();

            optionsBuilder.UseSqlServer(configuration.GetSection("ConnectionStrings")["SQL"]);

            var cultureInfo = new CultureInfo("en-US");

            using (var reader = new StreamReader(PATH))
                using (var context = new EFContextSQL(optionsBuilder.Options))
                {
                    var lineCount = File.ReadLines(PATH).Count();
                    var cont      = 1;
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(DELIMITER_CHARACTER);

                        var order = new Order
                        {
                            Id            = Guid.NewGuid().ToString(),
                            Region        = values[0],
                            Country       = values[1],
                            ItemType      = values[2],
                            SalesChannel  = values[3],
                            OrderPriority = values[4],
                            OrderDate     = DateTime.Parse(values[5], cultureInfo),
                            OrderId       = int.Parse(values[6]),
                            ShipDate      = DateTime.Parse(values[7], cultureInfo),
                            UnitsSlod     = int.Parse(values[8]),
                            UnitPrice     = decimal.Parse(values[9], cultureInfo),
                            UnitCost      = decimal.Parse(values[10], cultureInfo),
                            TotalCost     = decimal.Parse(values[11], cultureInfo),
                            TotalRevenue  = decimal.Parse(values[12], cultureInfo),
                            TotalProfi    = decimal.Parse(values[13], cultureInfo)
                        };

                        context.Add(order);
                        context.SaveChanges();

                        Console.Write("\r{0} de {1}", cont, lineCount);
                        cont++;
                    }

                    stopWatch.Stop();
                    var ts = stopWatch.Elapsed;

                    Console.WriteLine("");

                    Console.WriteLine($"Table 'Order' -> {context.Order.Count()} rows");
                    Console.WriteLine($"\t{ts.Seconds}.{ts.Milliseconds} sg.ms");

                    Console.WriteLine("");
                }
        }
Beispiel #5
0
        private static void SeedFromSQL(string options)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var optionsBuilder = new DbContextOptionsBuilder <EFContextSQL>();

            optionsBuilder.UseSqlServer(options);

            using (var context = new EFContextSQL(optionsBuilder.Options))
                using (var dbContextTransaction = context.Database.BeginTransaction())
                {
                    var profession = new Profession
                    {
                        AddedDate   = DateTime.Now,
                        Name        = "Progammer",
                        Description = "Computer Programmer"
                    };

                    if (!context.Profession.Any())
                    {
                        context.Profession.Add(profession);

                        profession = new Profession
                        {
                            AddedDate   = DateTime.Now,
                            Name        = "Analyst",
                            Description = "Computer Analyst"
                        };
                        context.Profession.Add(profession);

                        profession = new Profession
                        {
                            AddedDate   = DateTime.Now,
                            Name        = "Project Manager",
                            Description = "Project Manager"
                        };
                        context.Profession.Add(profession);
                    }

                    context.SaveChanges();

                    var user = new User
                    {
                        Name         = "Jesús",
                        Surname      = "Sánchez Corzo",
                        Username     = "******",
                        AddedDate    = DateTime.Now,
                        Age          = 46,
                        BirthDate    = new DateTime(1972, 8, 1),
                        Email        = "*****@*****.**",
                        Password     = "******",
                        ProfessionId = 1
                    };

                    if (!context.User.Any())
                    {
                        context.User.Add(user);
                    }

                    context.SaveChanges();

                    if (!context.Address.Any())
                    {
                        context.Address.Add(new Address
                        {
                            AddedDate = DateTime.Now,
                            UserId    = user.Id,
                            Street    = "Avda. de las Suertes",
                            Number    = 55
                        });
                        context.Address.Add(new Address
                        {
                            AddedDate = DateTime.Now,
                            UserId    = user.Id,
                            Street    = "C/ Dehesa de Vicálvaro",
                            Number    = 33
                        });
                    }

                    context.SaveChanges();

                    dbContextTransaction.Commit();

                    stopWatch.Stop();
                    var ts = stopWatch.Elapsed;

                    Console.WriteLine("");

                    Console.WriteLine($"Table User -> {context.User.Count()} rows");
                    Console.WriteLine($"Table Address -> {context.Address.Count()} rows");
                    Console.WriteLine($"Table Profession -> {context.Profession.Count()} rows");
                    Console.WriteLine($"\t{ts.Seconds}.{ts.Milliseconds} sg.ms");

                    Console.WriteLine("");
                }
        }
Beispiel #6
0
 public RepositoryTransaction(EFContextSQL context)
 {
     _context = context;
 }
Beispiel #7
0
 public ProfessionRepository(EFContextSQL context)
 {
     _context = context;
 }