MVC View에 IEnumerable로 전달되는 요약 역할을하는 클래스가 있습니다. 같은 클래스가 같습니다Linq Group by By 결과를 객체에 매핑
public class FixedLineSummary
{
public long? CustomerId { get; set; }
public string CustomerName { get; set; }
public int? NumberOfLines { get; set; }
public string SiteName { get; set; }
}
결과는 DB에서 반환 한 모든 항목이 있고 그래서 나는이 사용 요약 LINQ를 사용 : 내가하려고하면
var summary = (from r in result
let k = new {r.CustomerId, CustomerName = r.CompanyName, r.SiteName}
group r by k into t
select new
{
t.Key.CustomerId,
t.Key.CustomerName,
t.Key.SiteName,
Lines = t.Sum(r => r.lines)
});
과에 결과를 캐스팅 내 난 그냥 계속 점점 그러나 오브젝트 없다는 오류 :
Instance argument: cannot convert from 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<Domain.Entities.FixedLineSummary>'
내 클래스의 열거에 LINQ 쿼리의 결과를 주조하는 방법이 있나요?
어떻게 그들을 _cast_합니까? –
죄송합니다. .AsEnumerable(); –
GrahamJRoy