I am experiencing a few isssues when attempting to iterate through a hierachy of collections. I thought I had resolved these issues by doing a begin/commit after each process but that causes its own set of errors, but without this, I get an error after (X)number of iterations.
The below code works exactly as expected right up until the very last iteration, and then it will cause a Telerik.OpenAccess.Exceptions.UnsupportedException, I think when delving into this particular exception it is reporting that the result set has changed but I can confirm that if neccessary.
I am using Visual Studio 2010 and the latest version of ORM and a SSCE database.
Could you please look at my code below and let me know if I am not doing this correctly.
IObjectScope scope;
public Program()
{
WIESScopeProvider.AdjustForDynamicLoad();
scope = WIESScopeProvider.GetNewObjectScope();
versions = scope.GetOqlQuery<WIESVersion>().ExecuteList();
}
public void Execute()
{
try
{
using (SqlCeConnection conn = new SqlCeConnection(connstring))
{
conn.Open();
foreach (var version in versions)
{
IList<WIESSection> sections = version.Sections;
foreach (var section in sections)
{
IList<WIESSubSection> subsections = section.SubSections;
foreach(var subsection in subsections)
{
IList<WIESCalculation> calculations = subsection.Calculations;
foreach(var calculation in calculations)
{
//this can take up to 10 minutes depending on the amount of data within a table
ExecuteCalculation(conn, calculation);
//refresh the scope
scope.Transaction.Begin();
scope.Transaction.Commit();
}
}
}
}
conn.Close();
}
}
catch (Exception e) //todo
{
}
}