using System.Linq.Expressions; using Comal.Classes; using InABox.Core; using InABox.Database; namespace PRS.Shared; public class Update_6_43 : DatabaseUpdateScript { public override VersionNumber Version => new (6, 43); public override bool Update() { Logger.Send(LogType.Information, "", "Converting Supplier/Product Links"); List updates = new List(); var columns = Columns.None().Add(x => x.ID).Add(x=>x.Product.ID); columns.Add("ProductLink.ID"); CoreTable products = DbFactory.NewProvider(Logger.Main).Query(null, columns); foreach (var row in products.Rows) { Guid id = row.Get(x=>x.ID); Guid oldid = row.Get("ProductLink.ID"); Guid newid = row.Get(x=>x.Product.ID); if ((oldid != Guid.Empty) && (newid == Guid.Empty)) { var update = new SupplierProduct() { ID = id }; update.CommitChanges(); update.Product.ID = oldid; updates.Add(update); } } DbFactory.NewProvider(Logger.Main).Save(updates); return true; } }