Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs	(revision 1116)
@@ -48,12 +48,12 @@
         // lazy loading of problem from DB
         if (problem == null) {
-          IList<Statement> persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity));
-          if (persistedData.Count == 1) {
-            Literal persistedLiteral = (Literal)persistedData[0].Property;
+          var persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity));
+          if (persistedData.Count() == 1) {
+            Literal persistedLiteral = (Literal)persistedData.First().Property;
             this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
           } else
             this.problem = new Problem(); // no entry in the DB => create a new problem
         }
-        return problem; 
+        return problem;
       }
     }
@@ -69,6 +69,6 @@
       Store = store;
       guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length));
-      IList<Statement> names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity));
-      if (names.Count > 0) name = (string)((Literal)names[0].Property).Value;
+      var names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity));
+      if (names.Count() > 0) name = (string)((Literal)names.First().Property).Value;
       else name = guid.ToString();
     }
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetList.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetList.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetList.cs	(revision 1116)
@@ -41,5 +41,5 @@
         store = value;
         Action reload = ReloadList;
-        lock(dataSetList) {
+        lock (dataSetList) {
           dataSetList.Clear();
         }
@@ -58,8 +58,8 @@
 
     private void ReloadList() {
-      IList<Statement> statements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
-      foreach(Statement s in statements) {
+      var statements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
+      foreach (Statement s in statements) {
         DataSet d = new DataSet(store, s.Subject);
-        lock(dataSetList) {
+        lock (dataSetList) {
           dataSetList.Add(d);
         }
@@ -70,5 +70,5 @@
     public IEnumerator<DataSet> GetEnumerator() {
       List<DataSet> dataSets = new List<DataSet>();
-      lock(dataSets) {
+      lock (dataSets) {
         dataSets.AddRange(dataSetList);
       }
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetView.cs	(revision 1116)
@@ -84,6 +84,11 @@
         };
         worker.DoWork += delegate(object doWorkSender, DoWorkEventArgs doWorkArgs) {
-          worker.ReportProgress(10);
-          results.GetEntries().Last(); // preload list by accessing last element
+          int n = results.GetEntries().Count();
+          int i = 0;
+          // preload list 
+          foreach (var entry in results.GetEntries()) {
+            i++;
+            if((((i*100) / n) % 10) == 0) worker.ReportProgress((i * 100) / n);
+          }
           worker.ReportProgress(100);
         };
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Results.cs	(revision 1116)
@@ -64,13 +64,9 @@
 
     private List<ResultsEntry> entries = null;
+    private bool cached = false;
     public IEnumerable<ResultsEntry> GetEntries() {
-      if (entries == null)
-        Reload();
+      if (!cached)
+        return SelectRows();
       return entries.AsEnumerable();
-    }
-
-    internal void Reload() {
-      entries = SelectRows().ToList();
-      FireChanged();
     }
 
@@ -78,32 +74,44 @@
       if (store == null) yield break;
 
-      var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
-         .SelectMany(x => store.Select(new SelectFilter(
-           new Entity[] { (Entity)x.Property },
-           new Entity[] { Ontology.PredicateModelAttribute },
-           new Resource[] { Ontology.AnyEntity })))
-         .SelectMany(x =>
-           store.Select(
-              new SelectFilter(
-              new Entity[] { (Entity)x.Property },
-              new Entity[] { Ontology.PredicateModelAttributeName },
-              new Entity[] { Ontology.AnyEntity })).Select(y =>
-                new {
-                  Model = x.Subject,
-                  Attribute = (Entity)x.Property,
-                  AttributeName = (Literal)y.Property
-                }))
-         .SelectMany(x =>
-           store.Select(
-             new Statement(x.Attribute, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))
-             .Select(y =>
-               new {
-                 Model = x.Model.Uri,
-                 AttributeName = x.AttributeName.Value,
-                 AttributeValue = ((Literal)y.Property).Value
-               })).GroupBy(x => x.Model);
+      var models = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity));
 
+      //var results = store.Select(new Statement(dataSetEntity, Ontology.PredicateHasModel, Ontology.AnyEntity))
+      //   .SelectMany(x => store.Select(new SelectFilter(
+      //     new Entity[] { (Entity)x.Property },
+      //     new Entity[] { Ontology.PredicateModelAttribute },
+      //     new Resource[] { Ontology.AnyEntity })))
+      //   .SelectMany(x =>
+      //     store.Select(
+      //        new SelectFilter(
+      //        new Entity[] { (Entity)x.Property },
+      //        new Entity[] { Ontology.PredicateModelAttributeName },
+      //        new Entity[] { Ontology.AnyEntity })).Select(y =>
+      //          new {
+      //            Model = x.Subject,
+      //            Attribute = (Entity)x.Property,
+      //            AttributeName = (Literal)y.Property
+      //          }))
+      //   .SelectMany(x =>
+      //     store.Select(
+      //       new Statement(x.Attribute, Ontology.PredicateModelAttributeValue, Ontology.AnyEntity))
+      //       .Select(y =>
+      //         new {
+      //           Model = x.Model.Uri,
+      //           AttributeName = x.AttributeName.Value,
+      //           AttributeValue = ((Literal)y.Property).Value
+      //         })).GroupBy(x => x.Model);
 
-      Random random = new Random();
+      entries = new List<ResultsEntry>();
+      foreach (var model in models) {
+        var attributes = store.Select(new Statement((Entity)model.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
+
+        foreach (var attr in attributes) {
+          var namesAndValues = store
+            .Select(new SelectFilter(new Entity[] { (Entity)attr.Property },
+              new Entity[] { Ontology.PredicateModelAttributeName, Ontology.PredicateModelAttributeValue },
+              new Entity[] { Ontology.AnyEntity }));
+        }
+      }
+
       foreach (var row in results) {
         ResultsEntry entry = new ResultsEntry(row.First().Model);
@@ -111,6 +119,10 @@
           entry.Set((string)attr.AttributeName, attr.AttributeValue);
         }
+        entries.Add(entry);
         yield return entry;
       }
+
+      FireChanged();
+      cached = true;
     }
 
@@ -120,5 +132,5 @@
       var attributeNames =
         store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
-        .Select(s => (string)((Literal)s.Property).Value)
+        .Select(s => (string)((Literal)s.Property).Value)        
         .Distinct();
       foreach (var name in attributeNames) {
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj	(revision 1116)
@@ -70,4 +70,5 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="IVariableBindings.cs" />
     <Compile Include="Ontology.cs" />
     <Compile Include="SelectFilter.cs" />
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IStore.cs	(revision 1116)
@@ -35,8 +35,5 @@
 
     [OperationContract]
-    IList<Statement> Select(Statement template);
-
-    [OperationContract(Name = "SelectFiltered")]
-    IList<Statement> Select(SelectFilter filter);
+    ICollection<IVariableBindings> Select(ICollection<Statement> query);
   }
 }
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IVariableBindings.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IVariableBindings.cs	(revision 1116)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB.Interfaces/IVariableBindings.cs	(revision 1116)
@@ -0,0 +1,33 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.ServiceModel;
+using System.Data;
+using System.Linq.Expressions;
+
+namespace HeuristicLab.CEDMA.DB.Interfaces {
+  public interface IVariableBindings : IEnumerable<KeyValuePair<string, object>> {
+  }
+}
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj	(revision 1116)
@@ -74,4 +74,5 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="VariableBindings.cs" />
     <Compile Include="Store.cs" />
     <Compile Include="HeuristicLabCedmaDbPlugin.cs" />
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/Store.cs	(revision 1116)
@@ -42,5 +42,5 @@
     private object bigLock = new object();
     public Store(string connectionString) {
-      lock(bigLock) {
+      lock (bigLock) {
         this.connectionString = connectionString;
         store = SemWeb.Store.Create(connectionString);
@@ -49,32 +49,39 @@
 
     public void Add(Statement statement) {
-      lock(bigLock) {
+      lock (bigLock) {
         store.Add(Translate(statement));
       }
     }
 
-    public IList<Statement> Select(Statement template) {
-      SemWeb.SelectResult result;
-      lock(bigLock) {
-        result = store.Select(Translate(template));
-      }
-      List<Statement> r = new List<Statement>();
-      foreach(SemWeb.Statement resultStatement in result) {
-        r.Add(Translate(resultStatement));
-      }
-      return r;
+    public ICollection<IVariableBindings> Select(ICollection<Statement> query) {
+      SemWeb.Query.QueryResultSink resultSink = new MyQueryResultSink();
+      Translate(query).Run(store, resultSink);
+      return resultSink.Bindings;
     }
 
-    public IList<Statement> Select(SelectFilter filter) {
-      SemWeb.SelectResult result;
-      lock(bigLock) {
-        result = store.Select(Translate(filter));
+    private SemWeb.Query.Query Translate(ICollection<Statement> query) {
+      SemWeb.Query.GraphMatch graphMatch = new SemWeb.Query.GraphMatch();
+      foreach(Statement statement in query) {
+        graphMatch.AddGraphStatement(Translate(statement));
       }
-      List<Statement> r = new List<Statement>();
-      foreach(SemWeb.Statement resultStatement in result) {
-        r.Add(Translate(resultStatement));
-      }
-      return r;
+      return graphMatch;
     }
+
+
+    //public ICollection<Statement> Select(Statement template) {
+    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
+    //  lock (bigLock) {
+    //    store.Select(Translate(template), memStore);
+    //  }
+    //  return memStore.Select(x=>Translate(x)).ToList();
+    //}
+
+    //public ICollection<Statement> Select(SelectFilter filter) {
+    //  SemWeb.MemoryStore memStore = new SemWeb.MemoryStore();
+    //  lock (bigLock) {
+    //    store.Select(Translate(filter), memStore);
+    //  }
+    //  return memStore.Select(x => Translate(x)).ToList();
+    //}
 
     private SemWeb.SelectFilter Translate(SelectFilter filter) {
@@ -91,7 +98,7 @@
 
     private SemWeb.Resource Translate(Resource prop) {
-      if(prop is Literal) {
+      if (prop is Literal) {
         return TranslateLiteral((Literal)prop);
-      } else if(prop is SerializedLiteral) {
+      } else if (prop is SerializedLiteral) {
         return TranslateLiteral((SerializedLiteral)prop);
       } else {
@@ -101,5 +108,5 @@
 
     private Statement Translate(SemWeb.Statement statement) {
-      if(statement.Object is SemWeb.Literal) {
+      if (statement.Object is SemWeb.Literal) {
         return new Statement(
           new Entity(statement.Subject.Uri),
@@ -122,22 +129,22 @@
 
     private SemWeb.Literal TranslateLiteral(SerializedLiteral l) {
-      if(l.RawData == null) return null;
+      if (l.RawData == null) return null;
       return new SemWeb.Literal(l.RawData, null, "serializedItem");
     }
 
     private SemWeb.Literal TranslateLiteral(Literal l) {
-      if(l.Value == null) return null;
-      if(l.Value is double) return SemWeb.Literal.FromValue((double)l.Value);
-      else if(l.Value is bool) return SemWeb.Literal.FromValue((bool)l.Value);
-      else if(l.Value is int) return SemWeb.Literal.FromValue((int)l.Value);
-      else if(l.Value is long) return SemWeb.Literal.FromValue((long)l.Value);
-      else if(l.Value is string) return SemWeb.Literal.FromValue((string)l.Value);
+      if (l.Value == null) return null;
+      if (l.Value is double) return SemWeb.Literal.FromValue((double)l.Value);
+      else if (l.Value is bool) return SemWeb.Literal.FromValue((bool)l.Value);
+      else if (l.Value is int) return SemWeb.Literal.FromValue((int)l.Value);
+      else if (l.Value is long) return SemWeb.Literal.FromValue((long)l.Value);
+      else if (l.Value is string) return SemWeb.Literal.FromValue((string)l.Value);
       else return new SemWeb.Literal(l.Value.ToString());
     }
 
     private Resource TranslateLiteral(SemWeb.Literal l) {
-      if(l.DataType == "serializedItem") {
+      if (l.DataType == "serializedItem") {
         return new SerializedLiteral(l.Value);
-      } else if(l.DataType != null) {
+      } else if (l.DataType != null) {
         return new Literal(l.ParseValue());
       } else {
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/VariableBindings.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/VariableBindings.cs	(revision 1116)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.DB/VariableBindings.cs	(revision 1116)
@@ -0,0 +1,63 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Data.Linq;
+using HeuristicLab.CEDMA.DB.Interfaces;
+using System.ServiceModel;
+using System.Data;
+using System.Data.Common;
+using System.Threading;
+using HeuristicLab.Data;
+using HeuristicLab.Core;
+using System.Xml;
+using System.IO;
+
+namespace HeuristicLab.CEDMA.DB {
+  [Serializable]
+  public class VariableBindings : IVariableBindings {
+
+    private List<KeyValuePair<string, object>> bindings;
+
+    public VariableBindings() {
+      bindings = new List<KeyValuePair<string, object>>();
+    }
+
+    #region IEnumerable<KeyValuePair<string,object>> Members
+
+    public IEnumerator<KeyValuePair<string, object>> GetEnumerator() {
+      return bindings.GetEnumerator();
+    }
+
+    #endregion
+
+    #region IEnumerable Members
+
+    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
+      return GetEnumerator();
+    }
+
+    #endregion
+  }
+}
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Dispatcher.cs	(revision 1116)
@@ -52,10 +52,10 @@
     private void FillDispatchQueue() {
       Dictionary<Entity, Dictionary<int, int>> numberOfModelsOfTargetVariableOfDataSet = new Dictionary<Entity, Dictionary<int, int>>();
-      IList<Statement> datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
+      var datasetStatements = store.Select(new Statement(Ontology.AnyEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
       foreach (Statement datasetStatement in datasetStatements) {
         numberOfModelsOfTargetVariableOfDataSet.Add(datasetStatement.Subject, new Dictionary<int, int>());
-        IList<Statement> modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
+        var modelStatements = store.Select(new Statement(datasetStatement.Subject, Ontology.PredicateHasModel, Ontology.AnyEntity));
         foreach (Statement modelStatement in modelStatements) {
-          IList<Statement> modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
+          var modelAttributeStatements = store.Select(new Statement((Entity)modelStatement.Property, Ontology.PredicateModelAttribute, Ontology.AnyEntity));
           foreach (Statement modelAttrStatement in modelAttributeStatements) {
             var targetVariableStatements = store.Select(new Statement((Entity)modelAttrStatement.Property, Ontology.PredicateModelAttributeName, Ontology.AnyEntity))
Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1115)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Server/Executer.cs	(revision 1116)
@@ -117,5 +117,5 @@
        
       byte[] serializedModel = PersistenceManager.SaveToGZip(bestModelScope.GetVariableValue("FunctionTree", false));
-      store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(serializedModel)));
+      store.Add(new Statement(modelEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(serializedModel))));
 
     }
