How to use isnull type decision in linqdatasource orderby?
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 开发者_Python百科to figure out what would work, if anything. I tried the ?? operator as well. Any ideas?
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);
@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.
精彩评论