这是数据结构,我从NHibernate Query
回来public Class PaperResult
{
public Guid SubjectId {get;set}
public Guid StudentId {get;set}
public string Name {get;set}
public string Email {get;set}
public int Marks {get;set}
}
我的疑问是
- var resultEntities = _repository.Query< PaperResult>()。where(t => t.Id == testId)
- studentResults = resultEntities.GroupBy(x => x.StudentId)
醇>
返回,IQueryable,现在我将它投射到类
中public Class StudentResult
{
public Guid StudentId {get;set}
public string Name {get;set}
public string Email {get;set}
public int Marks {get;set}
public IEnumerable<PaperResult> PaperResults {get;set;}
}
我试图使用下面的linq来展平结果,但是Nhibernate被抛出“方法或操作没有实现。”。
from paperResult in studentResults
let studentResult = paperResult.First()
select new StudentResult()
{
StudentId =studentResult.StudentId,
Name =studentResult.Name,
Email =studentResult.Email,
Marks =studentResult.Marks,
PaperResults =resultEntities.Where(x => x.StudentId ==studentResult.StudentId
select new PaperResult(){...}.ToList()
}
注意:代码是骨架代码。
此致
答案 0 :(得分:0)
你应该可以对一个无常类型进行投射。
然后投射到您想要的类型: q.AsEnumerable(),选择(...)