1
public List<ProjectImpacts> getProjectImpactsByProjeactIDAndImpactName(String prefe , String impcName)
{ 
    String xim =  cecbContext.Impacts.First(i=>i.impt_name.Contains(impcName)).impt_reference;

    IQueryable<ProjectImpacts> query = from c in cecbContext.ProjectImpacts
            join b in cecbContext.Impacts on c.impt_reference equals b.impt_reference             
            where c.proj_reference == prefe && c.impt_reference == xim
            select b.impt_name;

    List<ProjectImpacts> SelectedImpacts = query.ToList(); //query.Select(refe => new ProjectImpacts { impt_reference =   }).ToList();

    return SelectedImpacts;
}

我在此查询中遇到错误:

无法将类型“System.Linq.IQueryable”隐式转换为“System.Linq.IQueryable”。存在显式转换(您是否缺少演员表?)

4

1 回答 1

3

这是因为您的查询最后选择了一个名称:

IQueryable<ProjectImpacts> query = from c in cecbContext.ProjectImpacts
    join b in cecbContext.Impacts on c.impt_reference equals b.impt_reference             
    where c.proj_reference == prefe && c.impt_reference == xim
    // select b.impt_name; // <<== Replace this...
    select c;              // <<== with this.

T泛型的类型参数IQueryable<T>对应于查询中选择的对象的类型。由于您选择 a name(大概是 a string),因此您得到了IQueriable<string>. 一旦你选择c,即ProjectImpacts,你会得到IQueryable<ProjectImpacts>你的结果

于 2013-04-06T02:11:59.553 回答