LINQ查询的语法List< string>

LINQ查询的语法List< string>

问题描述:

我想尝试这样做...

I am trying to do something like this...

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正在说...

Visual Studio is saying...

无法将类型System.Linq.IQueryable>隐式转换为System.Collections.Generic.List。
显式转换存在(是否缺少转换?)

Cannot implicitly convert type 'System.Linq.IQueryable>' to 'System.Collections.Generic.List'. An explicit conversion exists (are you missing a cast?)

正确的语法是什么?

尝试

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;
}