1

Criteria を使用して次の機能を実行しようとしていますが、SQL のエラーを示す実行時エラーが発生します。

 var query = session.CreateCriteria<TableName>()
                       .Add(Restrictions.Disjunction()
                            .Add(Restrictions.InsensitiveLike("Property1", keyword, MatchMode.Anywhere))
                            .Add(Restrictions.InsensitiveLike("Property2", keyword, MatchMode.Anywhere)));

query.SetProjection(Projections.Count(Projections.Distinct(
                                    Projections.ProjectionList()
                                    .Add(Projections.Property("Property1"))
                                    .Add(Projections.Property("Property3"))
                                    )));

テーブル マッピングは次のようになります。

public class TableName
{
     public int Property1 {get;set;}
     public int Property2 {get;set;}
     public int Property3 {get;set;}
     public int Property4 {get;set;}
}

予測に基づいて個別の結果をカウントする必要があります。結果を行全体としてカウントしたくありません。

誰でもこれで私を助けてもらえますか?

- - - - - アップデート - - - - -

これは私が達成しようとしていることです:

select Count(*)

from 
(
    select distinct Property1 , Property2 
    from tableName
    where Property1 like '%t%' or Property3 like '%t%'
) As x
4

1 に答える 1

0

あなたの基準は、翻訳できれば、次のような SQL になります。

SELECT count(DISTINCT Property1, Property3) 
FROM TableName 
WHERE Property1 LIKE '%keyword%' OR Property2 LIKE '%keyword%'

これは機能しません。使用する

Projections.RowCount()  or  Projections.RowCountInt64()

COUNT(*) に相当します。おそらく、GROUP BY 句は (DISTINCT の代わりに) 意味があります。(LIKE '%keyword%' で検索するときに Int64 の結果カウントが必要ないことを願っています! ;-)

于 2013-11-05T17:13:11.277 に答える