2
我正在使用LINQ to SQL和LINQ dynamic where和order by。LINQ to SQL lambda exp。 OrderBy,Case When,Where Where
我想將下面的代碼(ASP)轉換爲C#.net。
function getTestimonialList(statusCd)
sWhere = ""
if statusCd <> "" then
sWhere = " where status='" & statusCd & "'"
end if
sqlStr="select * from testimonial" & sWhere & " order by case when status = 'P' then 1 when status = 'A' then 2 else 3 end, dateadded desc"
set rs=getResult(sqlStr)
set getTestimonialList=rs
end function
這裏是我的查詢:
var TestimonialList = from p in MainModelDB.Testimonials
where String.IsNullOrEmpty(statusCd)?"1=1":p.status== statusCd
orderby p.status == 'P' ? 1 : (p.status == 'A' ? 2 : 3)
orderby p.DateAdded descending
select p;
上面的例子不工作! ,任何想法,如果可能的話?任何其他方式來做到這一點?
感謝
您好!你是一個幫助我解決數十億問題的史詩傢伙。謝謝! ('OrderBy'子句工作得很好..) – 2013-09-16 12:30:48