I have a number of different data sources that I need to query and have been able to do confine all my queries to very simple expressions with no more than 2 conditions. An example of typical complexity of my lamba Expressions is:
b => b.user == "joe" && b.domain == "bloggs.com"
On my non-SQL data sources I'm ok as I can convert them to object lists and use a LINQ query such as:
public override T Get(List<T> assets, Expression<Func<T, bool>> whereClause)
{
return assets.Where(a => whereClause.Compile()(a)).FirstOrDefault();
}
My problem is when I need to query a relational database - I'm only really concerned with Postgresql and MySQL - I've been struggling a bit. I've got nHibernate to Linq "working" but have had some issues where it stalls and stops accessing the database or can't close connections, typical sort of things to expect from something in beta so I'm not complaining.
Because my queries are so simple and I am happy to build the SQL myself I'd like to know if there is a relatively painless way to turn my Expression's into SQL where clauses?
I've had a quick search around and found some samples and of course there are already some Linq-to-SQL engines so I know it can be done. The question is whether it's something I can whip up in a day or less of effort? That's what I'd estimate it would take me to find a compatible Linq-to-SQL library and load test it assuming it works out ok. I do have big performance considerations so raw SQL is preferrable for me instead of running through an ORM.