views:

381

answers:

1

I have recently had the need to write a fluent interface for C# that will essentially mirror SQL. Yes, I am aware of LINQ to SQL, but I'm interesting in getting "closer to the metal"--having something that essentially provides nothing more than an Intellisensified SQL shim within C#.

E.g.,

var fq = new FluentQuery();
Expression<Action> =
    () => fq.SELECT.DISTINCT(Foo.ID).FROM(Foo).WHERE(Foo.Age > 22);

Now, I was thinking that this concept could be generalised--that is, how about a general EBNF to fluent interface generator? Does anyone know if such a beast exists?

+2  A: 

I like it, but you have to make sure to return types like HasFromAndSelect or something like that so you don't end up with fq.SELECT(Foo.ID).SELECT(Foo.Age).WHERE(Foo.Age > 22) or fq.WHERE(Foo.Age > 22).SELECT(Foo.ID), etc.

There's much more thought that needs to go into this, including the fact that the CAPS LOCK MODE is hurting my eyes :)

Omer van Kloeten
The caps lock is deliberate - serves to visually differentiate the internal DSL that you're using; plus, SQL is generally specified canonically in caps.
Eric Smith