如何通过nhibernate /流利的nHibernate使用MYSQL BIT_COUNT函数?

问题描述

| 我正在做一些巫毒教,需要使用c#/ linq / fluent-nhibernate由bit_count运算符对结果进行排序。 这是我当前的订单说明:
orderby m.InitiatorInventory & wanted descending
我真正想要的是这样的东西
orderby BIT_COUNT(m.InitiatorInventory & wanted descending)
这是MysqL函数: http://dev.MysqL.com/doc/refman/5.0/zh-CN/bit-functions.html#function_bit-count     

解决方法

您可以使用
CreateSQLQuery
,也可以在NHibernate中注册自己的
BIT_COUNT
方言:
public class MyDialect : MySqlDialect
{
    public MyDialect()
    {
        RegisterFunction(\"bit_count\",new StandardSQLFunction(\"bit_count\",null));
    }
}
更多信息在这里。