private string GetOrderDataCSV() { int countLines = 0; if (CurrentInOrder == null) { return(null); } StringBuilder sb = new StringBuilder(); // 17. Always access the data context with a new EF-Database-Instance because the Entities in the root workflow-node are in DETACHED-State! using (MyCompanyDB dbApp = new MyCompanyDB()) { InOrder inOrder = dbApp.InOrder.Include(c => c.InOrderPos_InOrder) .Include("InOrderPos_InOrder.Material") .Where(c => c.InOrderID == CurrentInOrder.InOrderID) .FirstOrDefault(); if (inOrder != null) { sb.AppendLine(String.Format("{0};{1};", inOrder.InOrderNo, inOrder.InOrderDate)); foreach (var line in inOrder.InOrderPos_InOrder) { countLines++; sb.AppendLine(String.Format("{0};{1};", line.Material.MaterialNo, line.TargetQuantity)); } } } using (ACMonitor.Lock(_20015_LockValue)) { _CountLines = countLines; } return(sb.ToString()); }
/// <summary>(E) Method for local usage when instance is configured as a local service object at "\LocalServiceObjects"</summary> public double SumLines(MyCompanyDB dbApp, InOrder inOrder) { double sumTargetQuantity = 0.0; foreach (InOrderPos line in inOrder.InOrderPos_InOrder) { Add(dbApp, line, ref sumTargetQuantity); } return(sumTargetQuantity); }
public double SumLinesByID(Guid inOrderID) { // Implement stateless: Never use MyCompanyDB in a private Field! using (MyCompanyDB dbApp = new MyCompanyDB()) { double sumTargetQuantity = 0.0; foreach (InOrderPos line in dbApp.InOrderPos.Where(c => c.InOrderID == inOrderID)) { Add(dbApp, line, ref sumTargetQuantity); } return(sumTargetQuantity); } }
public static MyCompanyDB GetAppContextForBSO(ACComponent bso) { if (bso.ParentACComponent != null && bso.ParentACComponent.Database != null && bso.ParentACComponent.Database is MyCompanyDB) { return(bso.ParentACComponent.Database as MyCompanyDB); } MyCompanyDB dbApp = ACObjectContextManager.GetContext("BSOMyCompContext") as MyCompanyDB; if (dbApp == null) { Database parentIPlusContext = new Database(); dbApp = ACObjectContextManager.GetOrCreateContext <MyCompanyDB>("BSOMyCompContext", null, parentIPlusContext); } return(dbApp); }
protected InOrder GetInOrder(ACMethod acMethod) { if (acMethod == null) { return(null); } Guid inOrderID = (Guid)acMethod[InOrder.ClassName]; if (inOrderID == Guid.Empty) { return(null); } using (MyCompanyDB dbApp = new MyCompanyDB()) { return(dbApp.InOrder.Where(c => c.InOrderID == inOrderID) .SetMergeOption(System.Data.Objects.MergeOption.NoTracking) .FirstOrDefault()); } }
/// <summary>Implement stateless: Pass all necessary data instead using private fields. e.g. "sumTargetQuantity" is passed by reference</summary> private void Add(MyCompanyDB dbApp, InOrderPos line, ref double sumTargetQuantity) { sumTargetQuantity += line.TargetQuantity; }