小编Car*_*aro的帖子

Projections.Conditional - 如何使用它?

任何人都知道如何使用Projections.Conditional产生类似"case ... when ......"的东西.

以下代码提供了错误的查询:

IProjection isError = Projections.Conditional( Expression.Eq( "event.LogLevel", eLogLevel.Fatal.ToString( ) ), Projections.Constant( 1 ), Projections.Constant( 0 ) );

ICriteria criteria = Session.CreateCriteria( typeof( LogEvent ), "event" )
  .Add( Restrictions.Eq( "event.ApplID", "LogEventViewer" ) )
  .SetProjection( Projections.ProjectionList( )
    .Add( Projections.GroupProperty( "event.ApplID" ) )
    .Add( Projections.RowCount( ), "TotalCount" )
    .Add( Projections.Sum( isError ), "ErrorCount" )
  );
Run Code Online (Sandbox Code Playgroud)

生成的语句不完整,参数的顺序错误.

exec sp_executesql N'
  SELECT this_.strApplID as y0_
    , count(distinct this_.lngLogEventID) as y1_ 
    , sum((case when this_.strLogLevel = ? then ? else ? end)) …
Run Code Online (Sandbox Code Playgroud)

nhibernate icriteria

7
推荐指数
1
解决办法
3047
查看次数

标签 统计

icriteria ×1

nhibernate ×1