1
基于列的值我试图创建一个具有特定属性值的对象。我如何修改下面的查询来做到这一点?
//对象alertCode具有“code”属性,“description”代码将根据查询返回的alert_type值进行设置。我想创建一个基于列值的动态对象使用LINQ
var medicalcodes = new string[]{"M", "D", "5"};
var specialedcodes = new string []{"C", "I"};
var personalcommentscodes = new string []{"A"};
var academiccodes = new string[]{"R", "E", "S"};
List<alertCode alertCollections = (from a in alertinfo
select new alertCode{
where medicalcodes.Contains(a.alert_type)
code = 'M',
where specialcodes.Contains(a.alert_type)
code = 'S',
where personalcommentscodes.Contains(a.alert_type)
code = 'P',
where academiccodes.Contains(a.alert_type)
code = 'A',
desc = a.description
}).ToList();
谢谢你这个工作! – user1453999