views:

320

answers:

2

I have a sql stored procedure that uses isnull in the order by clause to order items by the latest reply date, or if that is null, by the posting date:

Example: ORDER BY isnull(rtb.LatestReplyDate,CB_TOPIC_DATE_POSTED) DESC

I am trying to get that to work in the orderby clause of a linqdatasource, to no avail yet: Example:

I know isnull isn't valid there, but I have yet to figure out what would work, if anything. I tried the ?? operator as well. Any ideas?

A: 

Check this linq..err...link

--Addendum

OrderBy(p => p.<YourCompareVariant> == null ? p.<IfNull> :  p.<IfNotNull>);

In your case:

OrderBy(p => p.LatestReplyDate == null ? p.LatestReplyDate : p.TopicDatePosted);
Shankar Ramachandran
I've already seen that, but it's not exactly what I was looking for. I was wondering if there was a way to very simply apply an isnull to the declarative linqdatasource, rather than messing around programatically in the code behind.
Michael A
@Michael pls see edit...is that something on the lines youre looking for
Shankar Ramachandran
A: 

@Xencor, here's what worked:

<asp:LinqDataSource OrderBy="(CB_DATE_LATEST_REPLY != null ? CB_DATE_LATEST_REPLY : CB_TOPIC_DATE_POSTED) desc" Select="new (CB_TOPIC_ID, CB_TOPIC_CAT_ID, CB_TOPIC_TITLE, CB_TOPIC_DATE_POSTED, CB_TOPIC_REPLY_COUNT, CB_DATE_LATEST_REPLY, LU_CB_CATEGORy, VIEW_ALL_USER)" TableName="CB_TOPICs" > </asp:LinqDataSource>

Which is obvious, I don't know how I managed to miss that. Such is life. Thanks for pointing me in right direction.

Michael A