Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 315893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:20:01+00:00 2026-05-12T08:20:01+00:00

I started out with this question , which I sort of answered there ,

  • 0

I started out with this question, which I sort of answered there, and now I’m asking the more fundamental question here. I’ve simplified the query down to this:

var q = from ent in LinqUtils.GetTable<Entity>()
        from tel in ent.Telephones.DefaultIfEmpty()
        select new {
          Name = ent.FormattedName,
          Tel = tel != null ? tel.FormattedNumber : "" // this is what causes the error
        };

tel.FormattedNumber is a property that combines the Number and Extension fields into a neatly formatted string. And here’s the error that results:

System.InvalidOperationException: Could not translate expression 'Table(Entity).SelectMany(ent => ent.Telephones.DefaultIfEmpty(), (ent, tel) => new <>f__AnonymousType0`2(Name = ent.FormattedName, Tel = IIF((tel != null), tel.FormattedNumber, "")))' into SQL and could not treat it as a local expression.

If I change the reference above from FormattedNumber to just plain Number, everything works fine.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:20:01+00:00Added an answer on May 12, 2026 at 8:20 am

    You could use AsEnumerable on the entity, but that would force it to bring back all the columns (even if not used); perhaps instead something like:

    var q1 = from ent in LinqUtils.GetTable<Entity>()
             from tel in ent.Telephones.DefaultIfEmpty()
             select new {
               Name = ent.FormattedName,
               Number = (tel == null ? null : ent.Number),
               Extension = (tel == null ? null : ent.Extension)
             };
    
    var q2 = from row in q1.AsEnumerable()
             select new {
                 row.Name,
                 FormattedNumber = FormatNumber(row.Number, row.Extension)
             };
    

    where FormatNumber is some method that takes the two and merges them, presumably re-used from your other (property) code.

    With LINQ-to-SQL, another option is to expose a UDF on the data-context that does the formatting inside the database; a slightly different example:

    var qry = from cust in ctx.Customers // and tel
              select new {
                  cust.Name,
                  FormattedNumber = ctx.FormatNumber(tel.Number, tel.Extension)
              };
    

    (which will do the work at the database; whether or not that is a good idea ;-p)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started by asking this question I wish to Select all rows which contain
Inspired by this question which started out innocently but is turning into a major
This question is for all NoSQL and specially mongoDB experts out there. I started
This question most closely relates to the asp.net mvc3 framework. It started out as
This started out as a general user question on Android forums. However it's become,
(there is a follow up to this question here ) I am working on
I am researching filling out a form programatically. I have seen this question which
Ok, I ran into this tree question which LOOKED simple, but started driving me
Out of the blue today I started getting this error in Visual Studio 2008
I just started getting this error today, seemingly out of nowhere. Any one see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.