我有这个mssql查询:
SELECT CONVERT(VARCHAR,DATEPART( "YYYY" ,A.Dispatch_DATE))
+ ' ' + CONVERT(VARCHAR,DATEPART( "MM" ,A.Dispatch_DATE)) + ' '
+ CONVERT(VARCHAR,DATEPART( "DD" ,A.Dispatch_DATE)) + ' '
+ CONVERT(VARCHAR,DATEPART( "HH" ,A.Dispatch_DATE))
AS DateNew, A.System_Key AS IdNew FROM Archive A,ArchiveDest AD
WHERE A.System_Key >= '201401240001'
AND A.System_Key <= '20140124FFFF'
AND (AD.System_Key = A.System_Key)
AND (AD.Dest_Key = '0001')
AND (AD.XMode = 'R' OR AD.XMode = 'K' OR AD.XMode = 'H')
但是此查询也必须在Oracle数据库中运行。 我想在Nhibernate QueryOver对象中翻译此查询(我已使用Fluent构建了所有db映射对象)。 这是我翻译的错误信息:
var hourResults = _session.QueryOver(() => a)
.JoinAlias(() => a.ArchiveDest, () => ad)
.Where(Restrictions.Ge(Projections.Property(() => a.SystemKey), "201401240001"))
.And(Restrictions.Le(Projections.Property(() => a.SystemKey), "20140124FFFF"))
.And(() => ad.ArchiveDestIdentifier.DestKey== "0001")
.And(new Conjunction().Add(() => ad.XMode == "R").Add( () => ad.XMode == "K" ).Add(() => ad.XMode == "H"))
.Select(Projections.Property(() => a.DispatchDate.YearPart() + " " + a.DispatchDate.MonthPart() + " " + a.DispatchDate.DayPart()),Projections.Property(()=> a.SystemKey)).List<object[]>();
这只是一个子查询,但我的问题是: 如何转换:
SELECT CONVERT(VARCHAR,DATEPART( "YYYY" ,A.Dispatch_DATE))
+ ' ' + CONVERT(VARCHAR,DATEPART( "MM" ,A.Dispatch_DATE)) + ' '
+ CONVERT(VARCHAR,DATEPART( "DD" ,A.Dispatch_DATE)) + ' '
+ CONVERT(VARCHAR,DATEPART( "HH" ,A.Dispatch_DATE))
到QueryOver选择投影?