开发者

Is there any .net class for query conditions like DetachedCriteria in Hibernate, but not rely on Hibernate?

开发者 https://www.devze.com 2023-01-19 06:11 出处:网络
I\'m writting a general DAO interface and facing a difficult in general Query operation. Query operation requires a set of query conditions. I\'d like to give a interface like

I'm writting a general DAO interface and facing a difficult in general Query operation. Query operation requires a set of query conditions. I'd like to give a interface like

IList<TEntity> Query(DetachedCriteria criteria);

But this makes the interface rely on nHibernate. If I want to use Linq or plain SQL, it is not easy to convert DetachedCriteria to them.

开发者_运维百科

I want to have a class that can wrap the query conditions just like DetachedCriteria in nHibernate, but can be converted to DetachedCriteria, or linq, or plain SQL.

I've once written a class in Java which wraps the query conditions and can be converted into plain SQL. I want to known whether there is any existing project in dot net that can do similiar work.


How about

Expression<Predicate<TEntity>>

You can then parse the expression tree and transform it into SQL. For linq you can even simply transform it into a where clause with the same predicate.

http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx describes the building of a complete Linq Provider, but you probably only need the equivalent of a where clause.


You can use IQueryable and build expression tree (the way which .NET Framework uses to build general query) or you can implement your own Specification pattern.

0

精彩评论

暂无评论...
验证码 换一张
取 消