Since I find it very interesting to play with FluentInterface and since I got lots of feedback to FluentInterface for one order line at a time, I'd like to share some ideas on how to make the currently very raw query API of NWorkspace a bit more fluent.

At present, the code for expressing a simple query that will return all people aged 42 goes like this:

IQuery q = new Query(typeof(Person));
q.AddCriterion(new CriterionInt("Age", NumericOperator.Equal, 42);
return _ws.GetByQuery(q);

I'm sure you'll agree that this is not the most fluent API ever, so let's see what we can do to improve it. First allow AddCriterion() to have several overloads and instantiate Criterion instances itself. Also assume that the Equal-operator is so common that we make it default if no operator has been provided. That simplifies things a bit.

IQuery q = new Query(typeof(Person));
q.AddCriterion("Age", 42);
return _ws.GetByQuery(q);

Let's change AddCriterion() into the intuitive method name of Where() instead (and let Where return IQuery).

IQuery q = new Query(typeof(Person))
  .Where("Age", 42);
return _ws.GetByQuery(q);

An alternative could be to let the IQuery hide the IWorkspace (and only inject it into the IQuery). And since Where() returns IQuery, we can call GetList() at last (or perhaps rather Select() to mimic SQL?).

return new Query(typeof(Person), _ws)
  .Where("Age", 42)
  .GetList();

Was I perhaps too influenced by LINQ syntax when I sketched the above? How would you improve the sketches? As usual, you can reach me here. For a start, I'm particularly interested to hear your ideas for such a simple case as this.