if you are using Linq2Sql
var results = datacontext.TableName.OrderBy(a => a.IsCompany ? a.CompanyName : a.LastName + ", " a.FirstName);
qntmfred
2009-07-27 03:45:55
if you are using Linq2Sql
var results = datacontext.TableName.OrderBy(a => a.IsCompany ? a.CompanyName : a.LastName + ", " a.FirstName);
SELECT CASE WHEN IsCompany = 1 THEN Company
ELSE LastName + ', ' + FirstName END AS DisplayName
FROM MyTable
ORDER BY DisplayName
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.