Bất cứ ai cũng biết làm thế nào để sử dụng Projections.Conditional để sản xuất cái gì đó như "trường hợp ... khi ..."Projections.Conditional - Cách sử dụng?
Đoạn mã dưới đây đưa ra một truy vấn sai:
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")
);
Những tuyên bố sản xuất là không đầy đủ và thứ tự của các tham số là sai.
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'
cách chính xác để sử dụng Projections.Conditional là gì?
Tôi nghĩ đó là lỗi. Tôi đã thử nhiều cách, và thứ tự của các tham số bị rối lên. Bạn đang sử dụng phiên bản NH nào? – asgerhallas