Skip to main content
 首页 » 编程设计

c#之无法将 lambda 表达式转换为类型 “string” 因为它不是委托(delegate)类型

2024年02月13日13duanxz

       var viewModel = new CoachIndexData(); 
 
        viewModel.Coaches = db.Coaches 
            .Include(i => i.Courses.Select(c => c.Department)) 
            .OrderBy(i => i.LastName); 

我不明白该怎么做。我是 ASP.NET MVC 的新手

请您参考如下方法:

取自Cannot convert lambda expression to type 'string' because it is not a delegate type

这对我有用。

Entity Framework 4.1 的 Include() 方法具有扩展方法,它还接受 lambda 表达式。所以

context.CustomerSites.Include(c => c.Customer); 

是完全有效的,你需要做的就是使用这个:

using System.Data.Entity;