I have the following predicate expression.
public IQueryable<T> Find(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
{
return //boolean
}
Here is where I am calling the method:
public void TestMethod1()
{
author.AuthorName = authorName;
using (var context = new AspBlogRepository<Author>())
{
if (context.Find(e => e.AuthorName == authorName))
{
//do nothing
}
context.Add(author);
}
}
I get an error saying that I you cannot convert an IQueryable to bool. I just want to be able to use my predicate expression to see if the author is already in the database.
Any help would be much appreciated.
Thanks!
The problem is here, if you indeed return boolean. If this method is inside your context, you would first need to resolve
Authorand then filter theAuthorsin your repository.If this is an EF context, and you have access to the EF context in your repository, you should be able to get the db set like this:
Then, you can run your predicate against the
entitySetreturning the filtered results.