小编Rog*_*Dai的帖子

LINQ to SQL lambda exp.OrderBy,Case When,Dynamic Where

我正在使用LINQ to SQL和LINQ动态在哪里和顺序.

我想将下面的代码(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
Run Code Online (Sandbox Code Playgroud)

这是我的查询:

var TestimonialList = from p in MainModelDB.Testimonials
                                  where String.IsNullOrEmpty(statusCd)?"1=1":p.status== statusCd
                              orderby p.status == 'P' ? 1 : (p.status == 'A' …
Run Code Online (Sandbox Code Playgroud)

c# lambda case linq-to-sql

2
推荐指数
1
解决办法
8001
查看次数

标签 统计

c# ×1

case ×1

lambda ×1

linq-to-sql ×1