Reputation: 27
in my win-form application, there is a method that combines some items that have been created previously, when the code is the first time to run, everything is fine, but in second and later runs combined items have the wrong length.
the code reads items from a SQL server using LINQ that has object type named "BetaData"
BetaData has a property named "Length" that is double. I have another list that processed items is stored in name "PartList" of type "ModifiedPartList".
in method length property changes for some items, but nothing gets stored or saved on SQL. this is the main method:
private List<ModifiedPartList> CombinePartList(ProgressBar Bar)
{
PartList.Clear();
List<BetaData> PartsinOrder = new List<BetaData>();
foreach (int view in Globals.Views)
{
List<int> OrdersInView = new List<int>();
foreach (Tuple<int, int> tuple in Globals.Orders)
{
if (tuple.Item1 == view)
{
if (!OrdersInView.Contains(tuple.Item2))
OrdersInView.Add(tuple.Item2);
}
}
if(OrdersInView.Count>0)
{
OrdersInView.Sort();
foreach (int order in OrdersInView)
{
//this is the section that problem occurs:
var parts = from BetaData in BetaContext.BetaDatas
where BetaData.ProjectName == Globals.ProjectName &&
BetaData.ProjectCode == Globals.ProjectCode &&
BetaData.ParentItem != Globals.ProjectName + "(" + Globals.ProjectCode + ")" &&
BetaData.View == view &&
BetaData.Order == order
select BetaData;
PartsinOrder.Clear();
PartsinOrder = parts.ToList();
foreach(BetaData part in PartsinOrder)
{
Bar.PerformStep();
}
}
}
PartsinOrder.Clear();
}
return PartList;
}
in the section that i have commented as problem location when the code is running for the second time, optimized length property is loaded to items instead of their original value from SQL. i cannot understand that because each time i read all items from SQL server. the point is in this stage after that i ran the method for several times and getting the wrong results when i close the program and start it again, on first run results are true. after selecting from SQL and converting it to list, i review items and their properties in list, and they are all true, but in foreach loop when each part comes into loop their Length property is wrong.
Upvotes: 0
Views: 73