小编Aru*_*esh的帖子

在C#中选择linq中的case

我怎样才能将以下sql语句转换为linq

 select  AdsProperties.AdsProID,
         AdsProperties.IsActive,
         AdsProperties.Name,
           case
                when AdsProperties.ControlType =1 then -- TextBox
                  'Textbox'
                when AdsProperties.ControlType =2 then -- DropDown
                  'Dropdown'
                when AdsProperties.ControlType =3 then -- ConboBox
                  'ComboBox'
                else -- RadioButton
                  'RadioButtont'
           end as ControlType   
   from CLF.utblCLFAdsPropertiesMaster as AdsProperties
Run Code Online (Sandbox Code Playgroud)

我试过这个

var query = from AdsProperties in db.utblCLFAdsPropertiesMasters
            select new
            {
                AdsProperties.AdsProID,
                AdsProperties.Name,
                AdsProperties.IsActive,
                ControlType = AdsProperties.ControlType == 1 ? (int?)"TextBox" : null,
                ControlType = AdsProperties.ControlType == 2 ? (int?)"Dropdown" : null,
                ControlType = AdsProperties.ControlType == 3 ? (int?)"ComboBox" : null,                 
                ControlType …
Run Code Online (Sandbox Code Playgroud)

c# linq

5
推荐指数
1
解决办法
628
查看次数

标签 统计

c# ×1

linq ×1