Update_6_43.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Linq.Expressions;
  2. using Comal.Classes;
  3. using InABox.Core;
  4. using InABox.Database;
  5. namespace PRS.Shared;
  6. public class Update_6_43 : DatabaseUpdateScript
  7. {
  8. public override VersionNumber Version => new (6, 43);
  9. public override bool Update()
  10. {
  11. Logger.Send(LogType.Information, "", "Converting Supplier/Product Links");
  12. List<SupplierProduct> updates = new List<SupplierProduct>();
  13. var columns = Columns.None<SupplierProduct>().Add(x => x.ID).Add(x=>x.Product.ID);
  14. columns.Add("ProductLink.ID");
  15. CoreTable products = DbFactory.NewProvider(Logger.Main).Query<SupplierProduct>(null, columns);
  16. foreach (var row in products.Rows)
  17. {
  18. Guid id = row.Get<SupplierProduct,Guid>(x=>x.ID);
  19. Guid oldid = row.Get<Guid>("ProductLink.ID");
  20. Guid newid = row.Get<SupplierProduct,Guid>(x=>x.Product.ID);
  21. if ((oldid != Guid.Empty) && (newid == Guid.Empty))
  22. {
  23. var update = new SupplierProduct() { ID = id };
  24. update.CommitChanges();
  25. update.Product.ID = oldid;
  26. updates.Add(update);
  27. }
  28. }
  29. DbFactory.NewProvider(Logger.Main).Save(updates);
  30. return true;
  31. }
  32. }