问题
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