Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>THIS IS THE CORRECT ASWER</strong><br/> Here is the working version for those who need it. The issue was a COMBINATION of things. The first of which was the following line was set to <code>True</code>:</p> <p><code>var where = PredicateBuilder.True&lt;vw_QuickFindResult&gt;();</code> </p> <p>It should be <code>False</code>...</p> <p><code>var where = PredicateBuilder.False&lt;vw_QuickFindResult&gt;();</code></p> <p>I don't know why...but other changes were needed also. </p> <pre><code>public static class PredicateBuilder { public static Expression&lt;Func&lt;T, bool&gt;&gt; True&lt;T&gt;() { return f =&gt; true; } public static Expression&lt;Func&lt;T, bool&gt;&gt; False&lt;T&gt;() { return f =&gt; false; } public static Expression&lt;Func&lt;T, bool&gt;&gt; Or&lt;T&gt;(this Expression&lt;Func&lt;T, bool&gt;&gt; expr1, Expression&lt;Func&lt;T, bool&gt;&gt; expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast&lt;Expression&gt;()); return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); } public static Expression&lt;Func&lt;T, bool&gt;&gt; And&lt;T&gt;(this Expression&lt;Func&lt;T, bool&gt;&gt; expr1, Expression&lt;Func&lt;T, bool&gt;&gt; expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast&lt;Expression&gt;()); return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters); } } public List&lt;QuickFindResult&gt; QueryDocuments(string searchText, string customerSiteId, List&lt;int&gt; filterIds) { var wildCards = new string[] { "*", "\"" }; var where = PredicateBuilder.False&lt;vw_QuickFindResult&gt;(); var searches = new List&lt;String&gt;(searchText.Split(' ')); // TODO: &lt;-- If more complex searches are needed we'll have to use RegularExpressions // SEARCH TEXT - WHERE Clause searches.ForEach(productName =&gt; { Boolean hasWildCards = (productName.IndexOfAny(new char[] { '"', '*' }) != -1); if (hasWildCards) { Int32 length = productName.Length; if (length &gt; 1) { string like = productName.Replace("%", "") .Replace("*", ""); string first = productName.Substring(0, 1); string last = productName.Substring(length - 1); // Contains if (wildCards.Contains(first) &amp;&amp; wildCards.Contains(last)) where = where.Or(p =&gt; p.DocumentName.Contains(like) || p.DocumentTitle.Contains(like)); // EndsWith else if (wildCards.Contains(first)) where = where.Or(p =&gt; p.DocumentName.EndsWith(like) || p.DocumentTitle.EndsWith(like)); // StartsWith else if (wildCards.Contains(last)) where = where.Or(p =&gt; p.DocumentName.StartsWith(like) || p.DocumentTitle.StartsWith(like)); // Contains (default) else where = where.Or(p =&gt; p.DocumentName.Contains(like) || p.DocumentTitle.Contains(like)); } else // Can only perform a "contains" where = where.Or(p =&gt; p.DocumentName.Contains(productName) || p.DocumentTitle.Contains(productName)); } else // Can only perform a "contains" where = where.Or(p =&gt; p.DocumentName.Contains(productName) || p.DocumentTitle.Contains(productName)); }); // FILTER IDS - WHERE Clause var filters = GetAllFilters().Where(x =&gt; filterIds.Contains(x.Id)).ToList(); filters.ForEach(filter =&gt; { if (!filter.IsSection) where = where.And(x =&gt; x.FilterName == filter.Name); }); var dataSource = DocumentCollectionService.ListQuickFind(where); var collection = new List&lt;QuickFindResult&gt;(); // Other UNRELATED stuff happens here... return collection; } public static List&lt;vw_QuickFindResult&gt; ListQuickFind(Expression&lt;Func&lt;vw_QuickFindResult, bool&gt;&gt; where) { var connectionString = GetConnectionString(ES_DOCUMENTS_CONNECTION_NAME); List&lt;vw_QuickFindResult&gt; results = null; using (HostingEnvironment.Impersonate()) { using (var dataContext = new ES_DocumentsDataContext(connectionString)) { var query = dataContext.vw_QuickFindResults.Where(where).OrderBy(x =&gt; x.DocumentName).OrderBy(x =&gt; x.DocumentTitle); results = query.ToList(); } } return results; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload