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 2213)
+++ branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/Model.cs	(revision 2217)
@@ -14,9 +14,8 @@
     }
 
-    public Model(Variable targetVariable, Algorithm algorithm, byte[] data)
+    public Model(Variable targetVariable, Algorithm algorithm)
       : this() {
       this.targetVariableId = targetVariable.Id;
       this.algorithmId = algorithm.Id;
-      this.Data = data;
     }
 
@@ -26,11 +25,4 @@
       get { return this.id; }
       private set { this.id = value; }
-    }
-
-    private byte[] data;
-    [Column(Storage = "data", DbType = "image", CanBeNull = false)]
-    public byte[] Data {
-      get { return this.data; }
-      set { this.data = value; }
     }
 
Index: branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelData.cs
===================================================================
--- branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelData.cs	(revision 2217)
+++ branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DataObjects/ModelData.cs	(revision 2217)
@@ -0,0 +1,48 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Data.Linq;
+using System.Data.Linq.Mapping;
+using System.Text;
+
+namespace HeuristicLab.Modeling.Database.SQLServerCompact {
+  [Table(Name = "ModelData")]
+  public class ModelData {
+
+    public ModelData() {
+      this.model = default(EntityRef<Model>);
+    }
+
+    public ModelData(Model model, byte[] data)
+      : base() {
+      this.modelId = model.Id;
+      this.data = data;
+    }
+
+
+    private int modelId;
+    [Column(Storage = "modelId", IsPrimaryKey = true)]
+    public int ModelId {
+      get { return this.modelId; }
+      private set {
+        if (modelId != value) {
+          if (model.HasLoadedOrAssignedValue)
+            throw new ForeignKeyReferenceAlreadyHasValueException();
+          modelId = value;
+        }
+      }
+    }
+
+    private EntityRef<Model> model;
+    [Association(Storage = "model", ThisKey = "ModelId", OtherKey = "Id", IsForeignKey = true)]
+    public Model Model {
+      get { return model.Entity; }
+    }
+
+    private byte[] data;
+    [Column(Storage = "data", DbType = "image", CanBeNull = false)]
+    public byte[] Data {
+      get { return this.data; }
+      private set { this.data = value; }
+    }
+  }
+}
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 2213)
+++ branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/DatabaseService.cs	(revision 2217)
@@ -45,5 +45,5 @@
 
       using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
-        model = new Model(target, algo, PersistenceManager.SaveToGZip(algorithm.Model.Data));
+        model = new Model(target, algo);
         model.TrainingSamplesStart = trainingSamplesStart;
         model.TrainingSamplesEnd = trainingSamplesEnd;
@@ -59,6 +59,10 @@
 
       using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
+        ctx.ModelData.InsertOnSubmit(new ModelData(model, PersistenceManager.SaveToGZip(algorithm.Model.Data)));
+      }
+
+      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
         foreach (string inputVariable in algorithm.Model.InputVariables) {
-          ctx.InputVariables.InsertOnSubmit(new InputVariable(model, variables[inputVariable]));          
+          ctx.InputVariables.InsertOnSubmit(new InputVariable(model, variables[inputVariable]));
         }
         ctx.SubmitChanges();
@@ -194,6 +198,6 @@
 
     public IEnumerable<IResult> GetAllResultsForInputVariables() {
-      using(ModelingDataContext ctx = new ModelingDataContext(connection) ){
-        return (from ir in ctx.InputVariableResults  select ir.Result).Distinct().ToList().Cast<IResult>();
+      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
+        return (from ir in ctx.InputVariableResults select ir.Result).Distinct().ToList().Cast<IResult>();
       }
     }
@@ -205,5 +209,4 @@
       ModelingDataContext ctx = new ModelingDataContext(connection);
       DataLoadOptions dlo = new DataLoadOptions();
-      dlo.LoadWith<ModelResult>(mr => mr.Model);
       dlo.LoadWith<ModelResult>(mr => mr.Result);
       ctx.LoadOptions = dlo;
@@ -214,4 +217,17 @@
       return results.ToList().Cast<IModelResult>();
     }
+
+    public void GetAllModelResults() {
+      ModelingDataContext ctx = new ModelingDataContext(connection);
+      DataLoadOptions dlo = new DataLoadOptions();
+      dlo.LoadWith<ModelResult>(mr => mr.Result);
+      dlo.LoadWith<ModelResult>(mr => mr.Model);
+      ctx.LoadOptions = dlo;
+
+      var results = from result in ctx.ModelResults
+                    select result;
+      results.ToList();     
+
+    }
     #endregion
 
@@ -221,6 +237,5 @@
       DataLoadOptions dlo = new DataLoadOptions();
       dlo.LoadWith<InputVariableResult>(ir => ir.Variable);
-      dlo.LoadWith<InputVariableResult>(ir => ir.Result);
-      dlo.LoadWith<InputVariableResult>(ir => ir.Model);
+      dlo.LoadWith<InputVariableResult>(ir => ir.Result);      
       ctx.LoadOptions = dlo;
 
@@ -241,4 +256,15 @@
       return ctx.Models.ToList().Cast<IModel>();
     }
+
+    public byte[] GetModelData(IModel model) {
+      using (ModelingDataContext ctx = new ModelingDataContext(connection)) {
+        var data = (from md in ctx.ModelData
+                    where md.Model == model
+                    select md);
+        if (data.Count() == 0)
+          return null;
+        return data.Single().Data;
+      }
+    }
     #endregion
 
Index: branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/HeuristicLab.Modeling.Database.SQLServerCompact-3.2.csproj
===================================================================
--- branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/HeuristicLab.Modeling.Database.SQLServerCompact-3.2.csproj	(revision 2213)
+++ branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/HeuristicLab.Modeling.Database.SQLServerCompact-3.2.csproj	(revision 2217)
@@ -122,4 +122,5 @@
     <Compile Include="DataObjects\InputVariableResult.cs" />
     <Compile Include="DataObjects\Model.cs" />
+    <Compile Include="DataObjects\ModelData.cs" />
     <Compile Include="HeuristicLabModelingDatabaseSQLServerCompactPlugin.cs" />
     <Compile Include="ModelingDataContext.cs" />
Index: branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/ModelingDataContext.cs
===================================================================
--- branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/ModelingDataContext.cs	(revision 2213)
+++ branches/HeuristicLab.Modeling Database Backend/sources/HeuristicLab.Modeling.Database.SQLServerCompact/3.2/ModelingDataContext.cs	(revision 2217)
@@ -33,4 +33,8 @@
     }
 
+    public Table<ModelData> ModelData {
+      get { return GetTable<ModelData>(); }
+    }
+
     public Table<InputVariableResult> InputVariableResults {
       get { return GetTable<InputVariableResult>(); }
