Converting Hibernate linq query to HQL

和自甴很熟 提交于 2019-12-08 02:58:18

问题


I understand that a IQueryable cannot be serialized. That means that queries can not be serialized, sent to a webservice, deserialized, queried and then sent back.

I was wondering if it is possible to convert a hibernate linq query to hql to be sent over the wire.

Is there another route I am missing?


回答1:


I think I've seen ADO.NET Data Services as advertised to work with NHibernate:

http://wildermuth.com/2008/07/20/Silverlight_2_NHibernate_LINQ_==_Sweet

http://ayende.com/Blog/archive/2008/07/21/ADO.Net-Data-Services-with-NHibernate.aspx

This is an old post, and not sure how maintained this feature is, but its worth a shot.




回答2:


I have a suggestion to you. Do not try to serialize query. Rather provide your user with an ability to compose arbitrary LINQ expression. Then send the expression over the wire (there is a gotcha here, since expressions are not serializable) to your server.

I have recently submitted to NHibernate.Linq project a change to their NHibernateExtensions class - a new ISession extension method List, which accepts an expression and fills the given list with the respective data, much like ICriteria.List method. The change was accepted (see here) so downloading the recent version of NHibernate.Linq should contain this method.

Anyway, you can find the details of this approach here.



来源:https://stackoverflow.com/questions/1192041/converting-hibernate-linq-query-to-hql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!