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.
Do it in memory:
Where
ToEnumerableis a nice little utility function:Note that I use
CustomerId = 0(notnull) to make sure the anonymous type match. It is even better to use a named type with the two fields (CustomerIdandName).