예제 #1
0
#pragma warning restore 0649
        public static void LoadSuppliers()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                List<SupplierFaxCSV> faxes = Csv.ReadFile<SupplierFaxCSV>("SupplierFaxes.csv", culture: CultureInfo.GetCultureInfo("es"));

                var faxDic = faxes.ToDictionary(r => r.SupplierID, r => r.Fax); 

                Administrator.SaveListDisableIdentity(db.Suppliers.Select(s =>
                    new SupplierEntity
                    {
                        CompanyName = s.CompanyName,
                        ContactName = s.ContactName,
                        ContactTitle = s.ContactTitle,
                        Phone = s.Phone.Replace(".", " "),
                        Fax = faxDic[s.SupplierID].Replace(".", " "),
                        Address = new AddressEntity
                        {
                            Address = s.Address,
                            City = s.City,
                            Region = s.Region,
                            PostalCode = s.PostalCode,
                            Country = s.Country
                        },
                    }.SetId(s.SupplierID)));
            }
        }
예제 #2
0
 public static void LoadPersons()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         db.Customers.Where(c => c.ContactTitle.Contains("Owner")).Select(c =>
              new PersonEntity
              {
                  FirstName = c.ContactName.Substring(0, c.ContactName.LastIndexOf(' ')),
                  LastName = c.ContactName.Substring(c.ContactName.LastIndexOf(' ') + 1),
                  DateOfBirth = null,
                  Title = null, 
                  Address = new AddressEntity
                  {
                      Address = c.Address,
                      City = c.City,
                      Region = c.Region,
                      PostalCode = c.PostalCode,
                      Country = c.Country,
                  },
                  Phone = c.Phone.Replace(".", " "),
                  Fax = c.Fax.Replace(".", " "),
                  Corrupt = true,
              }).SaveList();
     }
 }
예제 #3
0
 public static void LoadPersons()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         db.Customers.Where(c => c.ContactTitle.Contains("Owner")).Select(c =>
                                                                          new PersonEntity
         {
             FirstName   = c.ContactName.Substring(0, c.ContactName.LastIndexOf(' ')),
             LastName    = c.ContactName.Substring(c.ContactName.LastIndexOf(' ') + 1),
             DateOfBirth = null,
             Title       = null,
             Address     = new AddressEntity
             {
                 Address    = c.Address,
                 City       = c.City,
                 Region     = c.Region,
                 PostalCode = c.PostalCode,
                 Country    = c.Country,
             },
             Phone   = c.Phone.Replace(".", " "),
             Fax     = c.Fax.Replace(".", " "),
             Corrupt = true,
         }).SaveList();
     }
 }
예제 #4
0
        public static void LoadOrders()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var northwind = db.Customers.Select(a => new { a.CustomerID, a.ContactName }).ToList();

                var companies = Database.Query<CompanyEntity>().Select(c => new
                {
                    Lite = c.ToLite<CustomerEntity>(),
                    c.ContactName
                }).ToList();

                var persons = Database.Query<PersonEntity>().Select(p => new
                {
                    Lite = p.ToLite<CustomerEntity>(),
                    ContactName = p.FirstName + " " + p.LastName
                }).ToList();

                Dictionary<string, Lite<CustomerEntity>> customerMapping =
                    (from n in northwind
                     join s in companies.Concat(persons) on n.ContactName equals s.ContactName
                     select new KeyValuePair<string, Lite<CustomerEntity>>(n.CustomerID, s.Lite)).ToDictionary();

                db.Orders.GroupsOf(10).ProgressForeachDisableIdentity(typeof(OrderEntity), l => l.ToInterval(a => a.OrderID).ToString(), null, (orders, writer) =>
                {
                    using (OperationLogic.AllowSave<OrderEntity>())
                        orders.Select(o => new OrderEntity
                        {

                            Employee = Lite.Create<EmployeeEntity>(o.EmployeeID.Value),
                            OrderDate = o.OrderDate.Value,
                            RequiredDate = o.RequiredDate.Value,
                            ShippedDate = o.ShippedDate,
                            State = o.ShippedDate.HasValue ? OrderState.Shipped : OrderState.Ordered,
                            ShipVia = Lite.Create<ShipperEntity>(o.ShipVia.Value),
                            ShipName = o.ShipName,
                            ShipAddress = new AddressEntity
                            {
                                Address = o.ShipAddress,
                                City = o.ShipCity,
                                Region = o.ShipRegion,
                                PostalCode = o.ShipPostalCode,
                                Country = o.ShipCountry,
                            },
                            Freight = o.Freight.Value,
                            Details = o.Order_Details.Select(od => new OrderDetailsEntity
                            {
                                Discount = (decimal)od.Discount,
                                Product = Lite.Create<ProductEntity>(od.ProductID),
                                Quantity = od.Quantity,
                                UnitPrice = od.UnitPrice,
                            }).ToMList(),
                            Customer = customerMapping[o.CustomerID].RetrieveAndForget(),
                            IsLegacy = true,
                        }.SetId(o.OrderID)).SaveList();
                });

            }
        }
예제 #5
0
        public static void LoadOrders()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var northwind = db.Customers.Select(a => new { a.CustomerID, a.ContactName }).ToList();

                var companies = Database.Query <CompanyEntity>().Select(c => new
                {
                    Lite = c.ToLite <CustomerEntity>(),
                    c.ContactName
                }).ToList();

                var persons = Database.Query <PersonEntity>().Select(p => new
                {
                    Lite        = p.ToLite <CustomerEntity>(),
                    ContactName = p.FirstName + " " + p.LastName
                }).ToList();

                Dictionary <string, Lite <CustomerEntity> > customerMapping =
                    (from n in northwind
                     join s in companies.Concat(persons) on n.ContactName equals s.ContactName
                     select new KeyValuePair <string, Lite <CustomerEntity> >(n.CustomerID, s.Lite)).ToDictionary();

                db.Orders.GroupsOf(10).ProgressForeachDisableIdentity(typeof(OrderEntity), l => l.ToInterval(a => a.OrderID).ToString(), null, (orders, writer) =>
                {
                    using (OperationLogic.AllowSave <OrderEntity>())
                        orders.Select(o => new OrderEntity
                        {
                            Employee     = Lite.Create <EmployeeEntity>(o.EmployeeID.Value),
                            OrderDate    = o.OrderDate.Value,
                            RequiredDate = o.RequiredDate.Value,
                            ShippedDate  = o.ShippedDate,
                            State        = o.ShippedDate.HasValue ? OrderState.Shipped : OrderState.Ordered,
                            ShipVia      = Lite.Create <ShipperEntity>(o.ShipVia.Value),
                            ShipName     = o.ShipName,
                            ShipAddress  = new AddressEntity
                            {
                                Address    = o.ShipAddress,
                                City       = o.ShipCity,
                                Region     = o.ShipRegion,
                                PostalCode = o.ShipPostalCode,
                                Country    = o.ShipCountry,
                            },
                            Freight = o.Freight.Value,
                            Details = o.Order_Details.Select(od => new OrderDetailsEntity
                            {
                                Discount  = (decimal)od.Discount,
                                Product   = Lite.Create <ProductEntity>(od.ProductID),
                                Quantity  = od.Quantity,
                                UnitPrice = od.UnitPrice,
                            }).ToMList(),
                            Customer = customerMapping[o.CustomerID].RetrieveAndForget(),
                            IsLegacy = true,
                        }.SetId(o.OrderID)).SaveList();
                });
            }
        }
예제 #6
0
 public static void LoadRegions()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Regions.Select(r =>
             new RegionEntity
             {
                 Description = r.RegionDescription.Trim()
             }.SetId(r.RegionID)));
     }
 }
예제 #7
0
 public static void LoadRegions()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Regions.Select(r =>
                                                                 new RegionEntity
         {
             Description = r.RegionDescription.Trim()
         }.SetId(r.RegionID)));
     }
 }
예제 #8
0
 public static void LoadShippers()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Shippers.Select(s =>
             new ShipperEntity
             {
                 CompanyName = s.CompanyName,
                 Phone = s.Phone,
             }.SetId(s.ShipperID)));
     }
 }
예제 #9
0
 public static void LoadShippers()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Shippers.Select(s =>
                                                                  new ShipperEntity
         {
             CompanyName = s.CompanyName,
             Phone       = s.Phone,
         }.SetId(s.ShipperID)));
     }
 }
예제 #10
0
 public static void LoadCategories()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Categories.Select(s =>
             new CategoryEntity
             {
                 CategoryName = s.CategoryName,
                 Description = s.Description,
                 Picture = new EmbeddedFileEntity { FileName = s.CategoryName + ".jpg", BinaryFile = EmployeeLoader.RemoveOlePrefix(s.Picture.ToArray()) },
             }.SetId(s.CategoryID)));
     }
 }
예제 #11
0
 public static void LoadCategories()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Categories.Select(s =>
                                                                    new CategoryEntity
         {
             CategoryName = s.CategoryName,
             Description  = s.Description,
             Picture      = new EmbeddedFileEntity {
                 FileName = s.CategoryName + ".jpg", BinaryFile = EmployeeLoader.RemoveOlePrefix(s.Picture.ToArray())
             },
         }.SetId(s.CategoryID)));
     }
 }
예제 #12
0
 public static void LoadProducts()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Products.Select(s =>
             new ProductEntity
             {
                 ProductName = s.ProductName,
                 Supplier =  Lite.Create<SupplierEntity>(s.SupplierID.Value),
                 Category = Lite.Create<CategoryEntity>(s.CategoryID.Value),
                 QuantityPerUnit = s.QuantityPerUnit,
                 UnitPrice = s.UnitPrice.Value,
                 UnitsInStock = s.UnitsInStock.Value,
                 ReorderLevel = s.ReorderLevel.Value,
                 Discontinued = s.Discontinued,
             }.SetId(s.ProductID)));
     }
 }
예제 #13
0
 public static void LoadProducts()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         Administrator.SaveListDisableIdentity(db.Products.Select(s =>
                                                                  new ProductEntity
         {
             ProductName     = s.ProductName,
             Supplier        = Lite.Create <SupplierEntity>(s.SupplierID.Value),
             Category        = Lite.Create <CategoryEntity>(s.CategoryID.Value),
             QuantityPerUnit = s.QuantityPerUnit,
             UnitPrice       = s.UnitPrice.Value,
             UnitsInStock    = s.UnitsInStock.Value,
             ReorderLevel    = s.ReorderLevel.Value,
             Discontinued    = s.Discontinued,
         }.SetId(s.ProductID)));
     }
 }
예제 #14
0
 public static void LoadCompanies()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         db.Customers.Where(c => !c.ContactTitle.Contains("Owner")).Select(c =>
                                                                           new CompanyEntity
         {
             CompanyName  = c.CompanyName,
             ContactName  = c.ContactName,
             ContactTitle = c.ContactTitle,
             Address      = new AddressEntity
             {
                 Address    = c.Address,
                 City       = c.City,
                 Region     = c.Region,
                 PostalCode = c.PostalCode,
                 Country    = c.Country,
             },
             Phone = c.Phone.Replace(".", " "),
             Fax   = c.Fax.Replace(".", " "),
         }).SaveList();
     }
 }
예제 #15
0
        public static void LoadTerritories()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var regionDic = Database.RetrieveAll <RegionEntity>().ToDictionary(a => a.Id);

                var territories = (from t in db.Territories.ToList()
                                   group t by t.TerritoryDescription into g
                                   select new
                {
                    Description = g.Key.Trim(),
                    Id = g.Select(t => t.TerritoryID).OrderBy().First(),
                    RegionID = g.Select(r => r.RegionID).Distinct().Single(),
                }).ToList();

                Administrator.SaveListDisableIdentity(territories.Select(t =>
                                                                         new TerritoryEntity
                {
                    Description = t.Description.Trim(),
                    Region      = regionDic[t.RegionID]
                }.SetId(int.Parse(t.Id))));
            }
        }
예제 #16
0
        public static void LoadTerritories()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var regionDic = Database.RetrieveAll<RegionEntity>().ToDictionary(a => a.Id);

                var territories = (from t in db.Territories.ToList()
                                   group t by t.TerritoryDescription into g
                                   select new
                                   {
                                       Description = g.Key.Trim(),
                                       Id = g.Select(t => t.TerritoryID).OrderBy().First(),
                                       RegionID = g.Select(r => r.RegionID).Distinct().Single(),
                                   }).ToList();

                Administrator.SaveListDisableIdentity(territories.Select(t =>
                    new TerritoryEntity
                    {
                        Description = t.Description.Trim(),
                        Region = regionDic[t.RegionID]
                    }.SetId(int.Parse(t.Id))));
            }
        }
예제 #17
0
 public static void LoadCompanies()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         db.Customers.Where(c => !c.ContactTitle.Contains("Owner")).Select(c =>
             new CompanyEntity
             {
                 CompanyName = c.CompanyName,
                 ContactName = c.ContactName,
                 ContactTitle = c.ContactTitle,
                 Address = new AddressEntity
                 {
                     Address = c.Address,
                     City = c.City,
                     Region = c.Region,
                     PostalCode = c.PostalCode,
                     Country = c.Country,
                 },
                 Phone = c.Phone.Replace(".", " "),
                 Fax = c.Fax.Replace(".", " "),
             }).SaveList();
     }
 }
예제 #18
0
        public static void LoadEmployees()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var duplicateMapping = (from t in db.Territories.ToList()
                                        group int.Parse(t.TerritoryID) by t.TerritoryDescription into g
                                        where g.Count() > 1
                                        let min = g.Min()
                                                  from item in g.Except(new[] { min })
                                                  select new
                {
                    Min = min,
                    Item = item
                }).ToDictionary(a => a.Item, a => a.Min);

                var territoriesDic = Database.RetrieveAll <TerritoryEntity>().ToDictionary(a => a.Id);


                var exmployeeTerritories = (from e in db.Employees
                                            from t in e.EmployeeTerritories
                                            select new { e.EmployeeID, t.TerritoryID }).ToList()
                                           .AgGroupToDictionary(a => a.EmployeeID, gr =>
                                                                gr.Select(a => int.Parse(a.TerritoryID))
                                                                .Select(id => duplicateMapping.TryGet(id, id))
                                                                .Select(id => territoriesDic[id])
                                                                .Distinct().ToMList());


                Administrator.SaveListDisableIdentity(
                    from e in db.Employees
                    select new EmployeeEntity
                {
                    BirthDate       = e.BirthDate,
                    FirstName       = e.FirstName,
                    LastName        = e.LastName,
                    TitleOfCourtesy = e.TitleOfCourtesy,
                    HomePhone       = e.HomePhone,
                    Extension       = e.Extension,
                    HireDate        = e.HireDate,
                    Photo           = new FileEntity {
                        FileName = e.PhotoPath.AfterLast('/'), BinaryFile = RemoveOlePrefix(e.Photo.ToArray())
                    }.ToLiteFat(),
                    PhotoPath = e.PhotoPath,
                    Address   = new AddressEntity
                    {
                        Address    = e.Address,
                        City       = e.City,
                        Country    = e.Country,
                        Region     = e.Region,
                        PostalCode = e.PostalCode,
                    },
                    Notes       = e.Notes,
                    Territories = exmployeeTerritories[e.EmployeeID],
                }.SetId(e.EmployeeID));

                var pairs = (from e in db.Employees
                             where e.ReportsTo != null
                             select new { e.EmployeeID, e.ReportsTo });

                foreach (var pair in pairs)
                {
                    EmployeeEntity employee = Database.Retrieve <EmployeeEntity>(pair.EmployeeID);
                    employee.ReportsTo = Lite.Create <EmployeeEntity>(pair.ReportsTo.Value);
                    employee.Save();
                }
            }
        }
예제 #19
0
        public static void LoadEmployees()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var duplicateMapping = (from t in db.Territories.ToList()
                                        group int.Parse(t.TerritoryID) by t.TerritoryDescription into g
                                        where g.Count() > 1
                                        let min = g.Min()
                                        from item in g.Except(new[] { min })
                                        select new
                                        {
                                            Min = min,
                                            Item = item
                                        }).ToDictionary(a => a.Item, a => a.Min);

                var territoriesDic = Database.RetrieveAll<TerritoryEntity>().ToDictionary(a => a.Id);

                var exmployeeTerritories = (from e in db.Employees
                                            from t in e.EmployeeTerritories
                                            select new { e.EmployeeID, t.TerritoryID }).ToList()
                          .AgGroupToDictionary(a => a.EmployeeID, gr =>
                              gr.Select(a => int.Parse(a.TerritoryID))
                              .Select(id => duplicateMapping.TryGet(id, id))
                              .Select(id => territoriesDic[id])
                              .Distinct().ToMList());

                Administrator.SaveListDisableIdentity(
                    from e in db.Employees
                    select new EmployeeEntity
                    {
                        BirthDate = e.BirthDate,
                        FirstName = e.FirstName,
                        LastName = e.LastName,
                        TitleOfCourtesy = e.TitleOfCourtesy,
                        HomePhone = e.HomePhone,
                        Extension = e.Extension,
                        HireDate = e.HireDate,
                        Photo = new FileEntity { FileName = e.PhotoPath.AfterLast('/'), BinaryFile = RemoveOlePrefix(e.Photo.ToArray()) }.ToLiteFat(),
                        PhotoPath = e.PhotoPath,
                        Address = new AddressEntity
                        {
                            Address = e.Address,
                            City = e.City,
                            Country = e.Country,
                            Region = e.Region,
                            PostalCode = e.PostalCode,
                        },
                        Notes = e.Notes,
                        Territories = exmployeeTerritories[e.EmployeeID],
                    }.SetId(e.EmployeeID));

                var pairs = (from e in db.Employees
                             where e.ReportsTo != null
                             select new { e.EmployeeID, e.ReportsTo });

                foreach (var pair in pairs)
                {
                    EmployeeEntity employee = Database.Retrieve<EmployeeEntity>(pair.EmployeeID);
                    employee.ReportsTo = Lite.Create<EmployeeEntity>(pair.ReportsTo.Value);
                    employee.Save();
                }
            }
        }