我有这种情况。我使用此查询调用CreateQuery
,我得到了Exception。
string sql = "SELECT VALUE CP
FROM CIC_PRODUZIONE_OPERAZIONI_View AS CP
WHERE CP.CD_PLANT = 5
AND CP.CD_POSTI = 10946
AND (CP.FL_STATE IN {N'D',N'N',N'M'})
AND EXISTS (SELECT 1
FROM CIC_OPERAZIONI AS C
WHERE CP.CD_CIC_PRODUZIONE = C.CD_CIC_PRODUZIONE
AND C.CD_POSTI = 10894
AND C.AFCDOPER = (SELECT VALUE TOP (1) D.AFCDOPER FROM CIC_OPERAZIONI AS D
WHERE D.CD_CIC_PRODUZIONE = CP.CD_CIC_PRODUZIONE
AND D.AFCDOPER > CP.AFCDOPER
ORDER BY D.AFCDOPER))
ORDER BY CP.AFCDPROD, CP.FL_STATE, CP.AFESPSAP, CP.AFESPMOD, CP.AFCDOPER";
ObjectQuery<T> entities = CreateQuery<T>(sql);
这是例外:
EntitySqlException:参数类型'Edm.Decimal'和 'Transient.collection [Edm.Decimal(可空=真,默认值=精密= 4,刻度= 0)]' 与此操作不兼容。
问题似乎是当我尝试选择TOP
值时。
有什么建议吗?
修改
我不认为问题出现在表达式的右侧,因为子查询得到ICollection<decimal>
,而左边有一个十进制字段。
...
C.AFCDOPER = (SELECT VALUE TOP (1) D.AFCDOPER FROM CIC_OPERAZIONI AS D
WHERE D.CD_CIC_PRODUZIONE = CP.CD_CIC_PRODUZIONE
AND D.AFCDOPER > CP.AFCDOPER
...
怎么可能获得该集合的“第一”以避免异常?
答案 0 :(得分:0)
你试过吗?
Select Top(1) D.AFCDOPER FROM CIC_OPERAZIONI AS D
我认为这将在没有世界“价值”的情况下发挥作用。