c# Object properties is loading from cache
up vote
0
down vote
favorite
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.
c# winforms oop object
|
show 6 more comments
up vote
0
down vote
favorite
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.
c# winforms oop object
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
And may I advice you to reduce the complexity of theCombinePartListmethod by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.
– Peter Bons
yesterday
I can see a few calls toSaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?
– Handbag Crab
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday
|
show 6 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
c# winforms oop object
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.
c# winforms oop object
c# winforms oop object
edited 18 hours ago
asked yesterday
Reza
113
113
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
And may I advice you to reduce the complexity of theCombinePartListmethod by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.
– Peter Bons
yesterday
I can see a few calls toSaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?
– Handbag Crab
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday
|
show 6 more comments
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
And may I advice you to reduce the complexity of theCombinePartListmethod by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.
– Peter Bons
yesterday
I can see a few calls toSaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?
– Handbag Crab
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
And may I advice you to reduce the complexity of the
CombinePartList method by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.– Peter Bons
yesterday
And may I advice you to reduce the complexity of the
CombinePartList method by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.– Peter Bons
yesterday
I can see a few calls to
SaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?– Handbag Crab
yesterday
I can see a few calls to
SaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?– Handbag Crab
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday
|
show 6 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
the issue was solved using this article and refreshing context after retrieving data from SQL
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
the issue was solved using this article and refreshing context after retrieving data from SQL
add a comment |
up vote
1
down vote
the issue was solved using this article and refreshing context after retrieving data from SQL
add a comment |
up vote
1
down vote
up vote
1
down vote
the issue was solved using this article and refreshing context after retrieving data from SQL
the issue was solved using this article and refreshing context after retrieving data from SQL
answered 18 hours ago
Reza
113
113
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236874%2fc-sharp-object-properties-is-loading-from-cache%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Have you tried debugging the method? Also, you haven't posted the code where you do the actual saving of the changes.
– Peter Bons
yesterday
And may I advice you to reduce the complexity of the
CombinePartListmethod by splitting it up into smaller methods? The length and amount of nesting due to the many if/else constructs makes it very difficult to read and understand.– Peter Bons
yesterday
I can see a few calls to
SaveLength(). Is it possible you're overwriting the values in the database so when you run it for the second time you're actually loading those saved/changed values back in?– Handbag Crab
yesterday
@PeterBons yes i have, there is no residuals after running the method that may affect next run, i have debugged it step by step, and when sql selection is running, everything is fine, but when objects are passed into foreach loop they get their last edited value.
– Reza
yesterday
@HandbagCrab as you can see in begining of the method each time method runs "ClearSavedLengthes();" clear all parameters that have bin saved.
– Reza
yesterday