spyter
spyter

Reputation: 727

Creating a nhibernate like query builder

I am trying to create something similar to the nhibernate fluent syntax.

I have a class called Query (where t is my class representation of a sql table) and I want to add a Where expression so that it can generate a sql string internally to be executed. I'm simply doing this for learning purposes so that is why I am not using an actual ORM. I dont need anything complex, just trying to learn the basics on how something like this is built with a Func or Expression.

Any help would be greatly appreciated. Thanks!!

I basically want to call:

var query = new Query<MyDomainClass>().Where(x => x.Id == 1);

and have it create a query that says "SELECT * FROM MyDomainClass WHERE Id = 1";

I'm not sure how to get the where part of the object working.

Upvotes: 2

Views: 927

Answers (1)

Trevor Pilley
Trevor Pilley

Reputation: 16423

You need to parse the expression tree, see this link for a quick introduction.

Upvotes: 2

Related Questions