Index: /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs
===================================================================
--- /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs	(revision 2388)
+++ /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs	(revision 2389)
@@ -46,5 +46,5 @@
     public int Id {
       get { return this.id; }
-      private set { this.id = value; }
+      set { this.id = value; }
     }
 
Index: /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs
===================================================================
--- /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2388)
+++ /trunk/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2389)
@@ -95,7 +95,9 @@
     }
 
-    public IModel CreateModel(ModelType modelType, IAlgorithm algorithm, IVariable targetVariable,
-int trainingSamplesStart, int trainingSamplesEnd, int validationSamplesStart, int validationSamplesEnd, int testSamplesStart, int testSamplesEnd) {
-      return CreateModel(null, modelType, algorithm, targetVariable, trainingSamplesStart, trainingSamplesEnd, validationSamplesStart, validationSamplesEnd, testSamplesStart, testSamplesEnd);
+    public IModel CreateModel(int id, string modelName, ModelType modelType, IAlgorithm algorithm, IVariable targetVariable,
+        int trainingSamplesStart, int trainingSamplesEnd, int validationSamplesStart, int validationSamplesEnd, int testSamplesStart, int testSamplesEnd) {
+      Model m = (Model)CreateModel(modelName, modelType, algorithm, targetVariable, trainingSamplesStart, trainingSamplesEnd, validationSamplesStart, validationSamplesEnd, testSamplesStart, testSamplesEnd);
+      m.Id = id;
+      return m;
     }
 
@@ -142,8 +144,9 @@
 
     public Dataset GetDataset() {
-      if (ctx.Problems.Count() != 1)
-        throw new InvalidOperationException("Could not get dataset. No or more than one problems are persisted in the database.");
-      Problem problem = ctx.Problems.Single();
-      return problem.Dataset;
+      if (ctx.Problems.Count() > 1)
+        throw new InvalidOperationException("Could not get dataset. More than one problems are persisted in the database.");
+      if (ctx.Problems.Count() == 1)
+        return ctx.Problems.Single().Dataset;
+      return null;
     }
 
@@ -192,4 +195,15 @@
         ctx.SubmitChanges();
       }
+    }
+
+    public IInputVariable GetInputVariable(IModel model, string inputVariableName) {
+      var inputVariables = ctx.InputVariables.Where(i => i.Model == model && i.Variable.Name == inputVariableName);
+      if (inputVariables.Count() == 1)
+        return inputVariables.Single();
+
+      if (inputVariables.Count() > 1)
+        throw new ArgumentException("More than one input variable with the same name are for the given model persisted.");
+
+      return null;
     }
 
@@ -258,5 +272,5 @@
     }
 
-    public void PersistModelResults(IModel model,IEnumerable<IModelResult> modelResults) {
+    public void PersistModelResults(IModel model, IEnumerable<IModelResult> modelResults) {
       using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
         ctx.ModelResults.DeleteAllOnSubmit(GetModelResults(model).Cast<ModelResult>());
@@ -277,5 +291,5 @@
     }
 
-    public void PersistInputVariableResults(IModel model,IEnumerable<IInputVariableResult> inputVariableResults) {
+    public void PersistInputVariableResults(IModel model, IEnumerable<IInputVariableResult> inputVariableResults) {
       using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
         ctx.InputVariableResults.DeleteAllOnSubmit(GetInputVariableResults(model).Cast<InputVariableResult>());
@@ -306,8 +320,8 @@
 
     public IModel Persist(HeuristicLab.Modeling.IAnalyzerModel model, string algorithmName, string algorithmDescription) {
-      Algorithm algorithm = (Algorithm) GetOrPersistAlgorithm(algorithmName);
-      Variable targetVariable  = (Variable)GetVariable (model.TargetVariable);
-
-      Model m = (Model)CreateModel(model.Type, algorithm, targetVariable, model.TrainingSamplesStart, model.TrainingSamplesEnd,
+      Algorithm algorithm = (Algorithm)GetOrPersistAlgorithm(algorithmName);
+      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);
       PersistModel(m);
Index: /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModel.cs
===================================================================
--- /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModel.cs	(revision 2388)
+++ /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModel.cs	(revision 2389)
@@ -27,4 +27,5 @@
 namespace HeuristicLab.Modeling.Database {
   public interface IModel {
+    int Id { get; }
     IVariable TargetVariable { get; }
     IAlgorithm Algorithm { get; }
Index: /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs
===================================================================
--- /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs	(revision 2388)
+++ /trunk/sources/HeuristicLab.Modeling.Database/3.2/IModelingDatabase.cs	(revision 2389)
@@ -42,8 +42,8 @@
     IModel Persist(HeuristicLab.Modeling.IAnalyzerModel model, string algorithmName, string algorithmDescription);
 
-    IModel CreateModel(ModelType modelType, IAlgorithm algorithm, IVariable targetVariable,
-     int trainingSamplesStart, int trainingSamplesEnd, int validationSamplesStart, int validationSamplesEnd, int testSamplesStart, int testSamplesEnd);
     IModel CreateModel(string modelName, ModelType modelType, IAlgorithm algorithm, IVariable targetVariable,
       int trainingSamplesStart, int trainingSamplesEnd, int validationSamplesStart, int validationSamplesEnd, int testSamplesStart, int testSamplesEnd);
+    IModel CreateModel(int id,string modelName, ModelType modelType, IAlgorithm algorithm, IVariable targetVariable,
+    int trainingSamplesStart, int trainingSamplesEnd, int validationSamplesStart, int validationSamplesEnd, int testSamplesStart, int testSamplesEnd);
     void PersistModel(IModel model);
     void DeleteModel(IModel model);
@@ -55,4 +55,5 @@
     IPredictor GetModelPredictor(IModel model);
     void PersistPredictor(IModel model, IPredictor predictor);
+    IInputVariable GetInputVariable(IModel model, string inputVariableName);
 
     IAlgorithm GetOrPersistAlgorithm(string algorithmName);
