Note that there are some explanatory texts on larger screens.

plurals
  1. POLocal sequence cannot be used in LINQ to SQL implementation
    primarykey
    data
    text
    <p>I'm getting an error, see below, when I try to generate a list of the class MappedItem. In short the code example below tries to find products by category, date range and SKU. The requirement I have is that the user should be able to enter a comma separated list of SKUs and the search is to find any product whos SKU starts with one of the SKUs entered by the user. When I run the code, I get.</p> <p>Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator.</p> <p>The abbreviated sequence is this: </p> <p>Convert the comma separated string of SKUs into a list of strings.</p> <pre><code>string sku = TextSKU.Text; List&lt;string&gt; skuList = sku.Split(new char[] { ',' }).ToList(); </code></pre> <p>Define elsewhere in the code the class that will accept the search results.</p> <pre><code>public class MappedItem { public string ItemDescription { get; set; } public int ItemCount { get; set; } public MappedItem() { } public MappedItem(string itemDescription, int itemCount) { ItemDescription = itemDescription; ItemCount = itemCount; } } </code></pre> <p>Here's the query that I generate my results from </p> <pre><code>List&lt;MappedItem&gt; widgetItems = (from c1 in db.CCRCodes join pac in db.widgetAssignedCodes on c1.code_id equals pac.code_id join ph in db.widgetHistories on pac.history_id equals ph.history_id where ph.contact_dt.Value.Date &gt;= startDate &amp;&amp; ph.contact_dt.Value.Date &lt;= endDate &amp;&amp; (string.IsNullOrEmpty(baanCatFam) || ph.baan_cat_family_code == baanCatFam) &amp;&amp; (string.IsNullOrEmpty(baanCat) || ph.baan_cat_code == baanCat) &amp;&amp; (string.IsNullOrEmpty(baanSubCat) || (ph.baan_sub_cat_code == baanSubCat)) &amp;&amp; (string.IsNullOrEmpty(sku) || skuList.All(sl =&gt; ph.product_mod.StartsWith(sl))) group c1 by c1.code_desc into ct select new MappedItem { ItemDescription = ct.Key.ToUpper(), ItemCount = ct.Count() }).OrderByDescending(m =&gt; m.ItemCount) .ToList(); </code></pre> <p>I believe that the culprit is the line of code that I've extracted and displayed below.</p> <pre><code>skuList.All(sl =&gt; ph.product_mod.StartsWith(sl)) </code></pre> <p>This identifies all skus that start with an element from the skuList which is derived from a comma delimited lists of skus entered by the user. My question is, what causes this error, and given the code examples, what do I do to get around them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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