Dynamic LINQ Cast issue

会有一股神秘感。 提交于 2021-02-08 08:04:27

问题


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

it throw exception

')' or ',' expected

My Entity Framework version is 4.0. Any idea how to resolve this problem ?

Thanks in advance,

Brian


回答1:


you cann't use as inside function call, try change your code like this

queryable.Where("(PositionID.ToString().Contains(@0))", paramsObj); //PositionID is Int32

UPDATE:

most likely in your case may have to use custom function from db

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



来源:https://stackoverflow.com/questions/19578856/dynamic-linq-cast-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!