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 8394219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:59:57+00:00 2026-06-09T19:59:57+00:00

I am looking for a linq to entities query which does the equivalent of

  • 0

I am looking for a linq to entities query which does the equivalent of the following SQL.

select null, '<None>'
union select CustomerId, Customer from Customers

I would then bind the resulting list of objects (which could be instances of an explicit class or an anonymous class) as the list source for a combo box. I don’t need all the fields of the Customer entity class but if the resulting list of objects were instances of this class rather than a ‘stub’ class that wouldn’t be a big problem, but obviously there would be some memory wastage.

  • 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-06-09T19:59:58+00:00Added an answer on June 9, 2026 at 7:59 pm

    Do it in memory:

    Ext.ToEnumerable(new {CustomerId = 0, Name = "<none>"})
        .Concat(db.Customers
            .Select(c => new {CustomerId = c.CustomerId, Name = c.Name}).ToList());
    

    Where ToEnumerable is a nice little utility function:

    public static class Ext
    {
        public static IEnumerable<T> ToEnumerable<T>(params T[] items)
        {
            return items;
        }
    }
    

    Note that I use CustomerId = 0 (not null) to make sure the anonymous type match. It is even better to use a named type with the two fields (CustomerId and Name).

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

Sidebar

Related Questions

I'm looking for some assistance converting the following sql query to LINQ to entities
I was looking for linq to entities extension which allows to add OPTION(MAXDOP x)
I am using Linq-To-Entities to do a query which is returning only 947 rows
I'm trying to write the following LINQ-Entities query: Get a list of Questions, that
My problem is the following: I'm looking for a solution in LINQ which translates
I am looking for a way in LINQ to match the follow SQL Query.
I'm looking into LINQ and the query language appears (at least on the surface)
LINQ gurus, I am looking for help to write a query... I have a
I am looking for sample linq code snippet which uses System.Linq.Dynamic against a datatable.
I'm looking at using LINQ to SQL for a new project I'm working on,

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.