I managed to work out the problem.
Reading the below article properly details that if you are using the
predicate builder with an entity framework a few tweaks are required.
http://www.albahari.com/nutshell/linqkit.aspx
1. Call AsExpandable() on the Table<> object
2. Call Compile() on the expression variable, when used on an
EntitySet or EntityCollection.
The AsExpandable and Predicate Builder are all included in an assembly
here:
http://www.albahari.com/nutshell/LinqKit.zip
For anyone who might be interrested the working method looks something
like this:
public List<Document> GetDocumentList(bool published, int
page, int pageSize,List<String> searchTerm)
{
searchTerm = searchTerm.Select(a => a.Replace("\"", "
")).ToList();
var predicate = PredicateBuilder.True<Document>();
var allDocs = (from p in
GetDocumentsTable().Linq().AsExpandable()
where p.published == published select p);
foreach(string searchWord in searchTerm)
{
switch (searchWord.Substring(0, 1))
{
case "+":
predicate = predicate.And(p =>
p.LoweredContent.Contains(searchWord.Substring(1).ToLower()));
break;
case "-":
predicate = predicate.And(p => !
p.LoweredContent.Contains(searchWord.Substring(1).ToLower()));
break;
case " ":
predicate = predicate.And(p =>
p.LoweredContent.Contains(searchWord.Substring(1).ToLower()));
break;
default:
predicate = predicate.Or(p =>
p.LoweredContent.Contains(searchWord.ToLower()));
break;
}
}
return allDocs.Where(predicate.Compile()).Skip((page - 1)
* pageSize).Take(pageSize).ToList();