Jeder weiß, wie Projections.Conditional zu nutzen, um etwas wie zu produzieren „Fall ... wenn ...“Projections.Conditional - Wie benutzt man es?
Der folgende Code eine falsche Abfrage ergibt:
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")
);
Die erzeugte Erklärung unvollständig ist und die Reihenfolge der Parameter ist falsch.
exec sp_executesql N'
SELECT this_.strApplID as y0_
, count(distinct this_.lngLogEventID) as y1_
, sum((case when this_.strLogLevel = ? then ? else ? end)) as y2_
, this_.strApplID as y3_
FROM qryLogEvent this_
WHERE this_.strApplID = @p0
GROUP BY this_.strApplID'
,N'@p0 nvarchar(5),@p1 int,@p2 int,@p3 nvarchar(14)'
,@p0=N'Fatal',@p1=1,@p2=0,@p3=N'LogEventViewer'
Was ist der richtige Weg, Projektionen zu verwenden.Zusätzlich?
glaube ich ist es ein Bug. Ich habe es auf alle möglichen Arten versucht, und die Reihenfolge der Parameter ist verwickelt. Welche Version von NH verwenden Sie? – asgerhallas