0

我在 Oracle SQL 语法中有一个如下所示的 SQL 查询,我希望它在 LINQ 中相等。

Select Case When tbl.Id=1 then 1 else NULL End as col1,
Case When tbl.Id=2 then 2 else NULL End as col2,
Case When tbl.Id=3 then 3 else NULL End as col3
From Table1 tbl
4

2 回答 2

2

您将在 中使用条件运算Select

var result = 
    table1.Select(x => new
                       {
                           col1 = x.Id == 1 ? (int?)1 : null,
                           col3 = x.Id == 2 ? (int?)2 : null,
                           col3 = x.Id == 3 ? (int?)3 : null
                       });
于 2013-09-13T08:11:30.960 回答
1
var items = from item in Table1
            select new
            {
                 col1 = item.Id == 1 ? (int?)1 : null,
                 col3 = item.Id == 2 ? (int?)2 : null,
                 col3 = item.Id == 3 ? (int?)3 : null)
            };
于 2013-09-13T08:12:42.167 回答