查询时的LINQ大小写

我在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 

您将在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 }); 
 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) };