views:

45

answers:

2

Hi all,

I have a client application that connects to a server. The server uses hibernate for persistence and querying so it has a set of annotated hibernate objects for persistence.

The client sends HQL queries to the server and gets responses back. The client has an auto-generated set of objects that match the server hibernate objects for query results and basic persistence.

I would like to support using Linq to query as well as Hql as it makes the queries typesafe and quicker to build (no more typos in HQL string queries). I've looked around at the following but I can't see how to get them to fit with what I have.

  • NHibernate's Linq provider - requires using NHibernate ISession and ISessionFactory, which I don't have
  • LinqExtender - requires a lot of annotations on the objects and extending a base type, too invasive

What I really want is something that will generate give me a nice easy to process structure to build the HQL queries from. I've read most of a 15 page article written by one of the C# developers on how to create custom providers and it's pretty fraught, mainly because of the complexity of the expression tree.

Can anyone suggest an approach for implementing Linq -> HQL translation? Perhaps a library that will the cleanup of the expression tree into something more SQL/HQLish.

I would like to support select/from/where/group by/order by/joins. Not too worried about subqueries.

+1  A: 

I don't think there is any library that does this. You can write your own provider. There are toolkits that help you in writing such a provider. For instance IQToolkit. But please note that writing your own provider will still be a lot of work. I'm not sure if it is worth the investment.

Steven
+1  A: 

So I found this library re-linq which is what NHibernate uses to implement its LINQ functionality. Seems to tidy up a lot of the noise around the expression stuff, although there seems to be a fair bit to do to on top to create an implementation.

re-linq

Mike Q