我正在尝试做这样的事情......
public static List<string> GetAttachmentKeyList()
{
DataClassesDataContext dc = new DataClassesDataContext();
List<string> list = from a in dc.Attachments
select a.Att_Key.ToString().ToList();
return list;
}
Visual Studio正在说......
无法隐式转换类型'System.Linq.IQueryable&gt;'到'System.Collections.Generic.List'。 存在显式转换(您是否错过了演员?)
什么是正确的语法???
答案 0 :(得分:18)
试一试
public static List<string> GetAttachmentKeyList()
{
DataClassesDataContext dc = new DataClassesDataContext();
List<string> list = ( from a in dc.Attachments
select a.Att_Key.ToString() ).ToList();
return list;
}
答案 1 :(得分:11)
试试这个,
public static List<string> GetAttachmentKeyList()
{
DataClassesDataContext dc = new DataClassesDataContext();
return dc.Attachments.Select(a=>a.Att_Key).ToList();
}
答案 2 :(得分:2)
我猜它会像下面那样。
List<string> list = (from a in dc.Attachments
select a.Att_Key.ToString()).ToList<string>();
希望这会有所帮助!!