1
찾고있는 결과를 생성하는 다음 GROUP 문이 있습니다.LINQ 결과에 ENUM 설명 포함
그러나 아래의 4 행을 "s.ComplaintNatureTypeId.ToDescription()"에 의해 "group s"로 변경하여 결과가 숫자 키 값이 아닌 ENUM 설명으로 그룹화되도록하고 싶습니다.
줄을 변경하면 "메서드 'System.String ToDescription (System.Enum)'에 SQL에 대한 지원되는 번역이 없습니다."
참고 : ToDescription()은 열거 형에서 설명을 가져 오는 데 사용되는 열거 형 확장 메서드입니다.
var qry = from s in _db.Complaints
where s.Site.SiteDescription.Contains(searchTextSite)
&& (s.Raised >= startDate && s.Raised <= endDate)
group s by s.ComplaintNatureTypeId.ToString()
into grp
select new
{
Site = grp.Key,
Count = grp.Count()
};
return Json(qry.ToList(), JsonRequestBehavior.AllowGet);
열거 클래스 :
using System.ComponentModel;
namespace Emas.Model.Enumerations
{
public enum ComplaintNatureType
{
[Description("- Please Select -")]
Blank = 0,
[Description("Letter")]
LE = 1,
[Description("eMail")]
EM = 2,
[Description("Verbal")]
VE = 3,
[Description("Other [see comments]")]
OT = 4,
}
}
감사합니다. – John