我使用Entity Framework
连接到数据库。现在,我想使用List<Object>
Linq
收到的数据
所以,我有:
var listOfSettings = new List<AppSetting>();
var query = from appSetting in AppSettings
where appSetting.AppConfigID == appConfigId
select new AppSetting()
{
AppSettingID = Int16.Parse(appSetting.AppSettingID),
...
};
如何将AppSetting Object
添加到设置的List
?
答案 0 :(得分:2)
List<AppSetting> listOfSettings = (from appSetting in AppSettings
where appSetting.AppConfigID == appConfigId
select new AppSetting()
{
AppSettingID = Int16.Parse(appSetting.Name),
...
}).ToList();
答案 1 :(得分:0)
最后,我必须这样做:
var query = (AppSettings.Select(appSetting => new
{
AppSettingID = appSetting.AppSettingID,
...
}).Where(appSetting => appSetting.AppConfigID == appConfigId)).ToList();
listOfAppSettings.AddRange(query.Select(setting => new AppSetting()
{
AppSettingID = setting.AppSettingID,
...
}));