csharp 按sql #NHibernate分组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 按sql #NHibernate分组相关的知识,希望对你有一定的参考价值。

if (IsGroupByPhone != null && IsGroupByPhone.isEquality && IsGroupByPhone.Value == true)
            {
                /*
                select 
    max(Id) as Id
    from (select 
        m.Id as Id,
        CASE WHEN m.DirectionMessage = 1 THEN m."From" ELSE m."To" END  as Phone
            from UC_AsteriskCall ac
                join UC_Message m on ( ac.Id = m.Id )
                where m.IsDeleted = 0) as ttt group by Phone
                 */
                string queryDirectionMessage = "";
                if(DirectionMessage != null && DirectionMessage.isEquality)
                    queryDirectionMessage += $" and m.DirectionMessage = {(int)(DirectionMessage.Value)} ";
                if (listDirectionMessage != null && listDirectionMessage.isEquality && listDirectionMessage.Value != null && listDirectionMessage.Value.Count > 0)
                    queryDirectionMessage += $" and m.DirectionMessage in ( {String.Join("," , listDirectionMessage.Value)} ) ";

                string query = $"select  max(Id) as Id from (select  m.Id as Id, CASE WHEN m.DirectionMessage = 1 THEN m.\"From\" ELSE m.\"To\" END  as Phone from UC_AsteriskCall ac join UC_Message m on ( ac.Id = m.Id ) where m.IsDeleted = 0 {queryDirectionMessage}) as ttt group by Phone";
                query = $" this_1_.Id in ({query}) ";
                criteria.Add(Expression.Sql(new SqlString(query)));
            }

以上是关于csharp 按sql #NHibernate分组的主要内容,如果未能解决你的问题,请参考以下文章

csharp 标准sql #NHibernate

无法使用 Nhibernate 的 Linq 检索 Group By 实体或复合键

nHibernate 生成了这个奇怪的 SQL; SQLS 是不是按原样使用它?

csharp: NHibernate and Entity Framework (EF) (object-relational mapper)

csharp SqlFunction #NHibernate

csharp NHibernate驱动程序Oracle