Translate SQL command to Nhibernate Linq using Criteria or QueryOver - Count results of ditinct selected columns

笑着哭i 提交于 2019-12-11 04:50:11

问题


I'm trying to translate the following SQL statement into Nhibernate query using Criteria or QueryOver but it's not working!! the SQL command is:

select Count(*)

from 
(
    select distinct col1, col2, col3
    from tableName
    where col1 like '%t%' or col4 like '%t%'
) As x

It either counts the results were's no projection applied, or it gives me a run-time error regards using this

 query.SetProjection(Projections.Count(Projections.Distinct(
                                                   Projections.ProjectionList()
                                                        .Add(Projections.Property("col1"))
                                                        .Add(Projections.Property("col2"))
                                                        .Add(Projections.Property("col3"))
                                                        )));

Can anyone help me please?

Thanks

来源:https://stackoverflow.com/questions/19812544/translate-sql-command-to-nhibernate-linq-using-criteria-or-queryover-count-res

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