Wie kann ich trasfrom die folgende SQL-Anweisung in Linqwählen Fall in Linq in C#
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
Ich habe versucht, diese
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 = AdsProperties.ControlType == 4 ? (int?)"RadioButton" : null)
};
dt = query.CopyToDataTableExt();
aber ich erhalte diesen Fehler
`an anynomous type cannot have multiple properties with the same name`
Ich weiß, dass es einfach und einfach sein kann. Da ich jedoch neu in linq bin, habe ich nicht die richtige Erfahrung, um damit umzugehen. Jede Hilfe wäre willkommen. Danke im Voraus.
Sie können eine separate Methode für die switch-Anweisung verwenden und diese der Eigenschaft ControlType.e.g zuweisen. 'ControlType = GetControlType (AdsProperties.ControlType)' –
Warum nicht Enum zu ControlType anstelle von int verwenden? – Alex
Magische Saiten sind böse. – Aron