动态LINQ Cast问题 [英] Dynamic LINQ Cast issue
问题描述
When I try to execute this ESQL (Cast int to string) with dynamic linq (from this link)
queryable.Where("CAST(PositionID AS Edm.String).Contains(@0)", paramsObj); //PositionID is Int32
它抛出异常
')' or ',' expected
我的实体框架版本为4.0.您知道如何解决此问题吗?
My Entity Framework version is 4.0. Any idea how to resolve this problem ?
预先感谢
布莱恩
推荐答案
您不能在函数调用中使用 as
,请尝试更改代码
you cann't use as
inside function call, try change your code like this
queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32
更新:
最有可能的情况是您必须使用db中的自定义功能
most likely in your case may have to use custom function from db
更新2:
我认为您不能将esql与Dynamic LINQ一起使用,因为它通过自身规则来解析字符串条件,因此对于LINQ Dynamic LINQ来说,语法edsl可能是错误的,也不是所有的SQL构造都在LINQ to Entities中实现,因此如果要使用像运算符
一样,您必须使用仅适用于字符串
的包含,StartsWith,EndsWith
函数因此,为解决此问题,您可以使用存储过程和函数,eSQL命令或原始sql
UPDATE 2:
i think you cann't use esql with Dynamic LINQ, because it parse string conditions by self rules, so syntax edsl may be wrong for Dynamic LINQ, also not all SQL constructions implement in LINQ to Entities, so if you want use like operator
you must use Contains, StartsWith, EndsWith
functions that work only with string
So for solve this you can use storage procedures and functions, or eSQL command, or raw sql
这篇关于动态LINQ Cast问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!