views:

164

answers:

3
+1  A: 

if you are using Linq2Sql

var results = datacontext.TableName.OrderBy(a => a.IsCompany ? a.CompanyName : a.LastName + ", " a.FirstName);
qntmfred
But this would require me to return ALL records from the database into the application layer first? I'm trying to still only get the records I need from MSSQL
Alex
+2  A: 
SELECT CASE WHEN IsCompany = 1 THEN Company
    ELSE LastName + ', ' + FirstName END AS DisplayName
FROM MyTable
ORDER BY DisplayName
Shannon Severance
Can I do this with LINQ?
Alex
@Alex: It's server side SQL. Not sure on the method to call it from LINQ.
Shannon Severance
+2  A: 

Are you referring to Linq to SQL? If so, create a partial class with a DisplayName property built off of the suggested FirstName, LastName, IsCompany and Company logic. You will want to use the namespace and partial class name as found in the designer file. This post may be helpful.

Ben Griswold