Linq to NHibernate extensibility for custom string query operations?

大兔子大兔子 提交于 2019-12-06 04:28:25

问题


I would like to be able to use custom string querying within my NHibernate Linq expressions. Let's say for example (and this is just an example) I would like to be able to select entities containing a property which is an anagram of a particular string:

var myEntities = EntityRepository.AllEntities.Where(x => x.Description.IsAnagramOf('hits');

I imagine the steps involved in this process would be:

  1. Define a SQL Server UDF to determine whether two strings are anagrams.

  2. Define an extension method called IsAnagramOf() for the String class.

  3. (And this is the tricky one). Modify Linq to NHibernate's component for parsing expression trees so that it converts calls to the extension method into the appropriate SQL UDF call.

My question is this. Does Linq to NHibernate contain some kind of extensibility model enabling me to 'slot in' my own custom string operations, or would I literally have to modify the existing source code to add in my shiznit to the expression tree parsing component?


回答1:


The extensibility is built in NH 3.0 (final release next month).

You can see a full working example at http://fabiomaulo.blogspot.com/2010/07/nhibernate-linq-provider-extension.html



来源:https://stackoverflow.com/questions/4284694/linq-to-nhibernate-extensibility-for-custom-string-query-operations

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