Reputation: 517
I've searched and found this error all over the stackoverflow forum, but it applies differently each time and I'd like someone help me in this particular matter.
public IEnumerable<Project> FindRange(string filterExpression, string sortingExpression, int startIndex, int count)
{
try
{
using (BusinessContext context = new BusinessContext())
{
if (!String.IsNullOrWhiteSpace(filterExpression))
return context.Projects
.Where(filterExpression)
The last line being the one of the error...
Do you have any idea why is this happening? I've already added all the usings and dlls needed, being:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
What am I missing? I've got code structured the same way, working...
Upvotes: 2
Views: 5861
Reputation: 266
If your BusinessContext
class has a string property such as Name that you are wanting to filter on then your where expression should look something like
.Where(x => x.Name.ToLower().StartsWith(filterExpression.ToLower()))
Upvotes: 1
Reputation: 149050
It looks like you may be trying to use the Dynamic Linq library. In that case you need to ensure that you've added the NuGet package to your project and then include this namespace:
using System.Linq.Dynamic;
Upvotes: 1
Reputation: 51504
Your filterexpression parameter should not be a string
- it should be a Func<>
.
See http://msdn.microsoft.com/en-us/library/system.linq.enumerable.where(v=vs.100).aspx
Upvotes: 4