Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.CEDMA.Core/3.3/Console.cs	(revision 2203)
@@ -34,5 +34,5 @@
 namespace HeuristicLab.CEDMA.Core {
   public class Console : ItemBase, IEditable {
-    private static readonly string sqlServerCompactFile = AppDomain.CurrentDomain.BaseDirectory + "HeuristicLab.Modeling.database";
+    private static readonly string sqlServerCompactFile = AppDomain.CurrentDomain.BaseDirectory + "HeuristicLab.Modeling.database.sdf";
     private static readonly string sqlServerCompactConnectionString = @"Data Source=" + sqlServerCompactFile;
 
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariable.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariable.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariable.cs	(revision 2203)
@@ -15,6 +15,6 @@
     public InputVariable(Model model, Variable variable)
       : base() {
-      this.model.Entity = model;
-      this.variable.Entity = variable;
+      this.modelId = model.Id;
+      this.variableId = variable.Id;
     }
 
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariableResult.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariableResult.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/InputVariableResult.cs	(revision 2203)
@@ -16,7 +16,7 @@
     public InputVariableResult(InputVariable inputVariable, Result result, double value)
       : this() {
-      this.variable.Entity = (Variable)inputVariable.Variable;
-      this.model.Entity = (Model)inputVariable.Model;
-      this.result.Entity = result;
+      this.variableId = inputVariable.VariableId;
+      this.modelId = inputVariable.ModelId;
+      this.resultId = result.Id;
       this.value = value;
     }
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs	(revision 2203)
@@ -16,6 +16,6 @@
     public Model(Variable targetVariable, Algorithm algorithm, byte[] data)
       : this() {
-      this.TargetVariable = targetVariable;
-      this.Algorithm = algorithm;
+      this.targetVariableId = targetVariable.Id;
+      this.algorithmId = algorithm.Id;
       this.Data = data;
     }
@@ -52,16 +52,16 @@
     public Algorithm Algorithm {
       get { return this.algorithm.Entity; }
-      private set {
-        Algorithm previousValue = algorithm.Entity;
-        if (previousValue != value || (!algorithm.HasLoadedOrAssignedValue)) {
-          if (previousValue != null) {
-            algorithm.Entity = null;
-          }
-          algorithm.Entity =value;
-          if (value != null) {
-            algorithmId = value.Id;
-          }
-        }
-      }
+      //private set {
+      //  Algorithm previousValue = algorithm.Entity;
+      //  if (previousValue != value || (!algorithm.HasLoadedOrAssignedValue)) {
+      //    if (previousValue != null) {
+      //      algorithm.Entity = null;
+      //    }
+      //    algorithm.Entity = value;
+      //    if (value != null) {
+      //      algorithmId = value.Id;
+      //    }
+      //  }
+      //}
     }
 
@@ -87,16 +87,16 @@
     public Variable TargetVariable {
       get { return this.targetVariable.Entity; }
-      private set {
-        Variable previousValue = targetVariable.Entity;
-        if (previousValue != value || (!targetVariable.HasLoadedOrAssignedValue)) {
-          if (previousValue != null) {
-            targetVariable.Entity = null;
-          }
-          targetVariable.Entity = value;
-          if (value != null) {
-            targetVariableId = value.Id;
-          }
-        }
-      }
+      //private set {
+      //  Variable previousValue = targetVariable.Entity;
+      //  if (previousValue != value || (!targetVariable.HasLoadedOrAssignedValue)) {
+      //    if (previousValue != null) {
+      //      targetVariable.Entity = null;
+      //    }
+      //    targetVariable.Entity = value;
+      //    if (value != null) {
+      //      targetVariableId = value.Id;
+      //    }
+      //  }
+      //}
     }
 
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelResult.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelResult.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelResult.cs	(revision 2203)
@@ -15,6 +15,6 @@
     public ModelResult(Model model, Result result, double value)
       : this() {
-      this.Model = model;
-      this.Result = result;
+      this.modelId = model.Id;
+      this.resultId = result.Id;
       this.value = value;
     }
@@ -44,16 +44,16 @@
     public Model Model {
       get { return this.model.Entity; }
-      set {
-        Model previousValue = model.Entity;
-        if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
-          if (previousValue != null) {
-            model.Entity = null;
-          }
-          model.Entity = value;
-          if (value != null) {
-            modelId = value.Id;
-          } 
-        }
-      }
+      //set {
+      //  Model previousValue = model.Entity;
+      //  if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
+      //    if (previousValue != null) {
+      //      model.Entity = null;
+      //    }
+      //    model.Entity = value;
+      //    if (value != null) {
+      //      modelId = value.Id;
+      //    } 
+      //  }
+      //}
     }
 
@@ -79,16 +79,16 @@
     public Result Result {
       get { return this.result.Entity; }
-      set {
-        Result previousValue = result.Entity;
-        if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
-          if (previousValue != null) {
-            result.Entity = null;
-          }
-          result.Entity = value;
-          if (value != null) {
-            resultId = value.Id;
-          }
-        }
-      }
+      //set {
+      //  Result previousValue = result.Entity;
+      //  if (previousValue != value || (!model.HasLoadedOrAssignedValue)) {
+      //    if (previousValue != null) {
+      //      result.Entity = null;
+      //    }
+      //    result.Entity = value;
+      //    if (value != null) {
+      //      resultId = value.Id;
+      //    }
+      //  }
+      //}
     }
 
Index: /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs
===================================================================
--- /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2202)
+++ /branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2203)
@@ -54,8 +54,12 @@
 
         ctx.Models.InsertOnSubmit(model);
+
+        ctx.SubmitChanges();
+      }
+
+      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
         foreach (string inputVariable in algorithm.Model.InputVariables) {
           ctx.InputVariables.InsertOnSubmit(new InputVariable(model, variables[inputVariable]));
         }
-        ctx.SubmitChanges();
       }
 
@@ -69,5 +73,8 @@
           ctx.ModelResults.InsertOnSubmit(new ModelResult(model, result, value));
         }
-
+        ctx.SubmitChanges();
+      }
+
+      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
         IEnumerable<MethodInfo> inputVariableResultInfos = algorithm.Model.GetType().GetMethods().Where(
           info => info.GetParameters().Count() == 1 &&
@@ -95,5 +102,5 @@
           throw new InvalidOperationException("Could not get dataset. No or more than one problems are persisted in the database.");
 
-        Problem problem = ctx.Problems.ElementAt(0);
+        Problem problem = ctx.Problems.Single();
         return problem.Dataset;
       }
@@ -181,5 +188,5 @@
     public IEnumerable<IResult> GetAllResults() {
       using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        return ctx.Results.AsEnumerable().Cast<IResult>();
+        return ctx.Results.ToList().Cast<IResult>();
       }
     }
@@ -198,5 +205,5 @@
                     where result.Model == model
                     select result;
-      return results.AsEnumerable().Cast<IModelResult>();
+      return results.ToList().Cast<IModelResult>();
     }
     #endregion
@@ -204,7 +211,9 @@
     #region Model
     public IEnumerable<IModel> GetAllModels() {
-      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        return ctx.Models.AsEnumerable().Cast<IModel>();
-      }
+      ModelingDataContext ctx = new ModelingDataContext(connection);
+      DataLoadOptions dlo = new DataLoadOptions();
+      dlo.LoadWith<Model>(m => m.TargetVariable);
+      ctx.LoadOptions = dlo;
+      return ctx.Models.ToList().Cast<IModel>();
     }
     #endregion
