Index: trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs
===================================================================
--- trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2482)
+++ trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2525)
@@ -160,16 +160,14 @@
 
     public void PersistModel(IModel model) {
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        Model m = (Model)model;
-        //check if model has to be updated or inserted
-        if (ctx.Models.Any(x => x.Id == model.Id)) {
-          Model orginal = ctx.Models.GetOriginalEntityState(m);
-          if (orginal == null)
-            ctx.Models.Attach(m);
-          ctx.Refresh(RefreshMode.KeepCurrentValues, m);
-        } else
-          ctx.Models.InsertOnSubmit(m);
-        ctx.SubmitChanges();
-      }
+      Model m = (Model)model;
+      //check if model has to be updated or inserted
+      if (ctx.Models.Any(x => x.Id == model.Id)) {
+        Model orginal = ctx.Models.GetOriginalEntityState(m);
+        if (orginal == null)
+          ctx.Models.Attach(m);
+        ctx.Refresh(RefreshMode.KeepCurrentValues, m);
+      } else
+        ctx.Models.InsertOnSubmit(m);
+      ctx.SubmitChanges();
     }
 
@@ -198,14 +196,12 @@
     public void PersistProblem(Dataset dataset) {
       Problem problem;
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        if (ctx.Problems.Count() != 0)
-          throw new InvalidOperationException("Could not persist dataset. A dataset is already saved in the database.");
-        problem = new Problem(dataset);
-        ctx.Problems.InsertOnSubmit(problem);
-        foreach (string variable in dataset.VariableNames) {
-          ctx.Variables.InsertOnSubmit(new Variable(variable));
-        }
-        ctx.SubmitChanges();
-      }
+      if (ctx.Problems.Count() != 0)
+        throw new InvalidOperationException("Could not persist dataset. A dataset is already saved in the database.");
+      problem = new Problem(dataset);
+      ctx.Problems.InsertOnSubmit(problem);
+      foreach (string variable in dataset.VariableNames) {
+        ctx.Variables.InsertOnSubmit(new Variable(variable));
+      }
+      ctx.SubmitChanges();
     }
 
@@ -227,17 +223,15 @@
 
     public void PersistPredictor(IModel model, IPredictor predictor) {
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        Model m = (Model)model;
-        ctx.ModelData.DeleteAllOnSubmit(ctx.ModelData.Where(x => x.Model == m));
-        ctx.ModelResults.DeleteAllOnSubmit(ctx.ModelResults.Where(x => x.Model == m));
-        ctx.InputVariableResults.DeleteAllOnSubmit(ctx.InputVariableResults.Where(x => x.Model == m));
-        ctx.InputVariables.DeleteAllOnSubmit(ctx.InputVariables.Where(x => x.Model == m));
-
-        ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(predictor)));
-        foreach (string variableName in predictor.GetInputVariables())
-          ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
-
-        ctx.SubmitChanges();
-      }
+      Model m = (Model)model;
+      ctx.ModelData.DeleteAllOnSubmit(ctx.ModelData.Where(x => x.Model == m));
+      ctx.ModelResults.DeleteAllOnSubmit(ctx.ModelResults.Where(x => x.Model == m));
+      ctx.InputVariableResults.DeleteAllOnSubmit(ctx.InputVariableResults.Where(x => x.Model == m));
+      ctx.InputVariables.DeleteAllOnSubmit(ctx.InputVariables.Where(x => x.Model == m));
+
+      ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(predictor)));
+      foreach (string variableName in predictor.GetInputVariables())
+        ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
+
+      ctx.SubmitChanges();
     }
 
@@ -255,15 +249,13 @@
     public IAlgorithm GetOrPersistAlgorithm(string algorithmName) {
       Algorithm algorithm;
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        var algorithms = ctx.Algorithms.Where(algo => algo.Name == algorithmName);
-        if (algorithms.Count() == 0) {
-          algorithm = new Algorithm(algorithmName, "");
-          ctx.Algorithms.InsertOnSubmit(algorithm);
-          ctx.SubmitChanges();
-        } else if (algorithms.Count() == 1)
-          algorithm = algorithms.Single();
-        else
-          throw new ArgumentException("Could not get Algorithm. More than one algorithm with the name " + algorithmName + " are saved in database.");
-      }
+      var algorithms = ctx.Algorithms.Where(algo => algo.Name == algorithmName);
+      if (algorithms.Count() == 0) {
+        algorithm = new Algorithm(algorithmName, "");
+        ctx.Algorithms.InsertOnSubmit(algorithm);
+        ctx.SubmitChanges();
+      } else if (algorithms.Count() == 1)
+        algorithm = algorithms.Single();
+      else
+        throw new ArgumentException("Could not get Algorithm. More than one algorithm with the name " + algorithmName + " are saved in database.");
       return algorithm;
     }
@@ -271,15 +263,13 @@
     public IResult GetOrPersistResult(string resultName) {
       Result result;
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        var results = ctx.Results.Where(r => r.Name == resultName);
-        if (results.Count() == 0) {
-          result = new Result(resultName);
-          ctx.Results.InsertOnSubmit(result);
-          ctx.SubmitChanges();
-        } else if (results.Count() == 1)
-          result = results.Single();
-        else
-          throw new ArgumentException("Could not get result. More than one result with the name " + resultName + " are saved in database.");
-      }
+      var results = ctx.Results.Where(r => r.Name == resultName);
+      if (results.Count() == 0) {
+        result = new Result(resultName);
+        ctx.Results.InsertOnSubmit(result);
+        ctx.SubmitChanges();
+      } else if (results.Count() == 1)
+        result = results.Single();
+      else
+        throw new ArgumentException("Could not get result. More than one result with the name " + resultName + " are saved in database.");
       return result;
     }
@@ -287,15 +277,13 @@
     public IMetaData GetOrPersistMetaData(string metaDataName) {
       MetaData metadata;
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        var md = ctx.MetaData.Where(r => r.Name == metaDataName);
-        if (md.Count() == 0) {
-          metadata = new MetaData(metaDataName);
-          ctx.MetaData.InsertOnSubmit(metadata);
-          ctx.SubmitChanges();
-        } else if (md.Count() == 1)
-          metadata = md.Single();
-        else
-          throw new ArgumentException("Could not get metadata. More than one metadata with the name " + metaDataName + " are saved in database.");
-      }
+      var md = ctx.MetaData.Where(r => r.Name == metaDataName);
+      if (md.Count() == 0) {
+        metadata = new MetaData(metaDataName);
+        ctx.MetaData.InsertOnSubmit(metadata);
+        ctx.SubmitChanges();
+      } else if (md.Count() == 1)
+        metadata = md.Single();
+      else
+        throw new ArgumentException("Could not get metadata. More than one metadata with the name " + metaDataName + " are saved in database.");
       return metadata;
     }
@@ -318,9 +306,7 @@
 
     public void PersistModelResults(IModel model, IEnumerable<IModelResult> modelResults) {
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        ctx.ModelResults.DeleteAllOnSubmit(GetModelResults(model).Cast<ModelResult>());
-        ctx.ModelResults.InsertAllOnSubmit(modelResults.Cast<ModelResult>());
-        ctx.SubmitChanges();
-      }
+      ctx.ModelResults.DeleteAllOnSubmit(GetModelResults(model).Cast<ModelResult>());
+      ctx.ModelResults.InsertAllOnSubmit(modelResults.Cast<ModelResult>());
+      ctx.SubmitChanges();
     }
 
@@ -337,9 +323,7 @@
 
     public void PersistInputVariableResults(IModel model, IEnumerable<IInputVariableResult> inputVariableResults) {
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        ctx.InputVariableResults.DeleteAllOnSubmit(GetInputVariableResults(model).Cast<InputVariableResult>());
-        ctx.InputVariableResults.InsertAllOnSubmit(inputVariableResults.Cast<InputVariableResult>());
-        ctx.SubmitChanges();
-      }
+      ctx.InputVariableResults.DeleteAllOnSubmit(GetInputVariableResults(model).Cast<InputVariableResult>());
+      ctx.InputVariableResults.InsertAllOnSubmit(inputVariableResults.Cast<InputVariableResult>());
+      ctx.SubmitChanges();
     }
 
@@ -351,9 +335,7 @@
 
     public void PersistModelMetaData(IModel model, IEnumerable<IModelMetaData> modelMetaData) {
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        ctx.ModelMetaData.DeleteAllOnSubmit(GetModelMetaData(model).Cast<ModelMetaData>());
-        ctx.ModelMetaData.InsertAllOnSubmit(modelMetaData.Cast<ModelMetaData>());
-        ctx.SubmitChanges();
-      }
+      ctx.ModelMetaData.DeleteAllOnSubmit(GetModelMetaData(model).Cast<ModelMetaData>());
+      ctx.ModelMetaData.InsertAllOnSubmit(modelMetaData.Cast<ModelMetaData>());
+      ctx.SubmitChanges();
     }
 
@@ -366,34 +348,31 @@
     public IModel Persist(HeuristicLab.Modeling.IAnalyzerModel model, string algorithmName, string algorithmDescription) {
       Algorithm algorithm = (Algorithm)GetOrPersistAlgorithm(algorithmName);
-      Variable targetVariable = (Variable)GetVariable(model.TargetVariable);
+      Variable targetVariable = (Variable) GetVariable(model.TargetVariable);
       Model m = (Model)CreateModel(null, model.Type, algorithm, targetVariable, model.TrainingSamplesStart, model.TrainingSamplesEnd,
         model.ValidationSamplesStart, model.ValidationSamplesEnd, model.TestSamplesStart, model.TestSamplesEnd);
-
-      using (ModelingDataContext ctx = new ModelingDataContext(this.ConnectionString)) {
-        ctx.Models.InsertOnSubmit(m);
-        ctx.SubmitChanges();
-        ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(model.Predictor)));
-        foreach (string variableName in model.Predictor.GetInputVariables())
-          ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
-
-        foreach (KeyValuePair<string, double> pair in model.MetaData) {
-          MetaData metaData = (MetaData)GetOrPersistMetaData(pair.Key);
-          ctx.ModelMetaData.InsertOnSubmit(new ModelMetaData(m, metaData, pair.Value));
+      ctx.Models.InsertOnSubmit(m);
+      ctx.SubmitChanges();
+      ctx.ModelData.InsertOnSubmit(new ModelData(m, PersistenceManager.SaveToGZip(model.Predictor)));
+
+      foreach (string variableName in model.Predictor.GetInputVariables())
+        ctx.InputVariables.InsertOnSubmit(new InputVariable(m, (Variable)GetVariable(variableName)));
+
+      foreach (KeyValuePair<string, double> pair in model.MetaData) {
+        MetaData metaData = (MetaData)GetOrPersistMetaData(pair.Key);
+        ctx.ModelMetaData.InsertOnSubmit(new ModelMetaData(m, metaData, pair.Value));
+      }
+
+      foreach (KeyValuePair<ModelingResult, double> pair in model.Results) {
+        Result result = (Result)GetOrPersistResult(pair.Key.ToString());
+        ctx.ModelResults.InsertOnSubmit(new ModelResult(m, result, pair.Value));
+      }
+
+      foreach (InputVariable variable in ctx.InputVariables.Where(iv => iv.Model == m)) {
+        foreach (KeyValuePair<ModelingResult, double> variableResult in model.GetVariableResults(variable.Variable.Name)) {
+          Result result = (Result)GetOrPersistResult(variableResult.Key.ToString());
+          ctx.InputVariableResults.InsertOnSubmit(new InputVariableResult(variable, result, variableResult.Value));
         }
-
-        foreach (KeyValuePair<ModelingResult, double> pair in model.Results) {
-          Result result = (Result)GetOrPersistResult(pair.Key.ToString());
-          ctx.ModelResults.InsertOnSubmit(new ModelResult(m, result, pair.Value));
-        }
-
-        foreach (InputVariable variable in ctx.InputVariables.Where(iv => iv.Model == m)) {
-          foreach (KeyValuePair<ModelingResult, double> variableResult in model.GetVariableResults(variable.Variable.Name)) {
-            Result result = (Result)GetOrPersistResult(variableResult.Key.ToString());
-            ctx.InputVariableResults.InsertOnSubmit(new InputVariableResult(variable, result, variableResult.Value));
-          }
-        }
-
-        ctx.SubmitChanges();
-      }
+      }
+      ctx.SubmitChanges();
 
       //if connected to database return inserted model
Index: trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/PredictorPersister.cs
===================================================================
--- trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/PredictorPersister.cs	(revision 2482)
+++ trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/PredictorPersister.cs	(revision 2525)
@@ -37,12 +37,13 @@
       DatabaseService db = new DatabaseService(database);
       db.Connect();
-      if (db.GetDataset() == null)
-        db.PersistProblem(ds);
+      Dataset temp = db.GetDataset();
+      if(temp == null)      
+        db.PersistProblem(ds);      
 
-      IAnalyzerModel model = new AnalyzerModel();
+      IAnalyzerModel model = new AnalyzerModel();                 
       DefaultModelAnalyzerOperators.PopulateAnalyzerModel(scope, model, modelType);
-
       db.Persist(model, algorithm, algorithm);
       db.Disconnect();
+      
 
       return null;
