简体   繁体   English

CreateQuery上的EntitySqlException和类型不匹配

[英]EntitySqlException on CreateQuery and type mismatch

I have this situation. 我有这种情况。 I call CreateQuery with this query and I get Exception. 我用此查询调用CreateQuery并得到异常。

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);

This is the Exception: 这是例外:

EntitySqlException: The argument types 'Edm.Decimal' and 'Transient.collection[Edm.Decimal(Nullable=True,DefaultValue=,Precision=4,Scale=0)]' are incompatible for this operation. EntitySqlException:参数类型'Edm.Decimal'和'Transient.collection [Edm.Decimal(Nullable = True,DefaultValue =,Precision = 4,Scale = 0)]'与该操作不兼容。

The problem seems to be when I try to select the TOP value. 问题似乎出在我尝试选择TOP值时。

Any suggestion? 有什么建议吗?

EDIT 编辑

I undestand that the problem is on the right side of the expression because the subquery get an ICollection<decimal> and on the left I have a decimal field. 我无法理解问题出在表达式的右侧,因为子查询获得了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

... ...

how could it be possible to get the "First" of that collection to avoid to get in exception? 如何获得该集合的“第一”以避免出现异常?

Did you try ? 你试过了吗 ?

Select Top(1) D.AFCDOPER   FROM CIC_OPERAZIONI AS D

I think this will work without the world "VALUE" . 我认为这将在没有世界“ VALUE”的情况下起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM