Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq "Could not translate expression... into SQL and could not treat it as a local expression."
    text
    copied!<p>I started out with <a href="https://stackoverflow.com/questions/1262736/only-one-expression-can-be-specified-in-the-select-list-when-the-subquery-is-not">this question</a>, which I sort of answered <a href="https://stackoverflow.com/questions/1262736/only-one-expression-can-be-specified-in-the-select-list-when-the-subquery-is-not/1262794#1262794">there</a>, and now I'm asking the more fundamental question here. I've simplified the query down to this:</p> <pre><code>var q = from ent in LinqUtils.GetTable&lt;Entity&gt;() from tel in ent.Telephones.DefaultIfEmpty() select new { Name = ent.FormattedName, Tel = tel != null ? tel.FormattedNumber : "" // this is what causes the error }; </code></pre> <p><code>tel.FormattedNumber</code> is a property that combines the <code>Number</code> and <code>Extension</code> fields into a neatly formatted string. And here's the error that results:</p> <pre><code>System.InvalidOperationException: Could not translate expression 'Table(Entity).SelectMany(ent =&gt; ent.Telephones.DefaultIfEmpty(), (ent, tel) =&gt; new &lt;&gt;f__AnonymousType0`2(Name = ent.FormattedName, Tel = IIF((tel != null), tel.FormattedNumber, "")))' into SQL and could not treat it as a local expression. </code></pre> <p>If I change the reference above from <code>FormattedNumber</code> to just plain <code>Number</code>, everything works fine.</p> <p>But I do want the formatted number to display nicely in my list. What do you recommend as the neatest, cleanest way of doing so?</p>
 

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