I'm consuming an Odata v4 service using Odata Client Code generator proxy class.
MetroContext = new MetroContainer(new Uri(@"http://localhost:56222/service"));
IQueryable<Patient> query = MetroContext.Patients;
query = query.Where(x => x.FirstName == "john");
Above code is working fine. But I need to build queries dynamically. So I have tried following:
MetroContext = new MetroContainer(new Uri(@"http://localhost:56222/service"));
IQueryable<Patient> query = MetroContext.Patients;
ParameterExpression pe = Expression.Parameter(typeof(Patient), "patient");
Expression left = Expression.Property(pe, "FirstName");
Expression right = Expression.Constant("john");
Expression predicateBody = Expression.Equal(left, right);
query = query.Provider.CreateQuery<Patient>(predicateBody);
When I run the program I'm getting an error message:
Error translating Linq expression to URI: The binary operator 'Equal' is not supported.
- Why I'm getting this error and how can I solve this?
- How can I create dynamic queries by combining methods such as
Contains()
,StartsWith()
?