C# Linq到Sql-类型“System.String”不支持序列运算符

C# Linq到Sql-类型“System.String”不支持序列运算符,c#,linq-to-sql,windows-phone-8,datacontext,C#,Linq To Sql,Windows Phone 8,Datacontext,当从内存中的样本数据填充Students集合时,下面的代码可以工作,但查询数据库时,我得到一个System.NotSupportedException。我正在做一个WindowsPhone8项目 List<CustomGrouping<Student>> groupings = (from student in dataContext.Students orderby student.FirstName orderby studen

当从内存中的样本数据填充Students集合时,下面的代码可以工作,但查询数据库时,我得到一个System.NotSupportedException。我正在做一个WindowsPhone8项目

List<CustomGrouping<Student>> groupings =
    (from student in dataContext.Students
        orderby student.FirstName
        orderby student.LastName         
    group student by Char.ToLower(student.FirstName.First()) into grouping        
    select new CustomGrouping<Student>(
        grouping.Key, grouping.AsEnumerable())).ToList();
为什么数据库查询会出现这种情况?我如何解决此问题?

不支持student.FirstName.First。尝试:

student.FirstName.Substring(0, 1).ToLower()
或:


相反,我需要的是字符而不是字符串。第一个建议返回一个字符串和char.ToLowerstudent.FirstName[0]仍然抛出NotSupportedException方法“char-ToLowerChar”不支持到SQL的转换。第二个建议不是如何实现扩展方法。@Pantelis坦率地说,很难;使用第一个版本,在完成数据库查询后,将长度为1的字符串更改为char。LINQ to SQL希望使用字符串
student.FirstName[0].ToLower()