将Linq中的列连接到SQL选择

时间:2016-07-14 04:23:53

标签: sql-server linq linq-to-sql linq-to-entities linq-to-xml

我想根据一列的条件连接两个列值。

我正在尝试这样

select
{
     Orders=r.ordercode.length==0?r.order1:r.ordercode.length==3?r.order1+r.order2+r.order3
}

2 个答案:

答案 0 :(得分:0)

Orders = r.ordercode.length == 0?r.order1:r.ordercode.length == 3?string.concat(r.order1,“,”,r.order2,“,”,r.order3 ): “”

答案 1 :(得分:0)

试试这个

select
{
     Orders = (
                (r.ordercode.length == 0 || r.ordercode.length == 3) ? 
                    String.Format("{0}, {1}, {2}", r.order1, r.order2, r.order3) : 
                    String.Empty
              )
}