Dynamic LINQ Cast issue

c#-4.0 casting dynamic-linq entity-framework-4

Question

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
1
10/25/2013 12:01:22 AM

Popular Answer

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

0
11/7/2013 5:54:17 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow