那是我的实体模型LINQ到实体GROUPBY和concatinate列
public class Warning
{
public int ID { get; set; }
public string WarningCId { get; set; }
public int WarningYearCounter { get; set; }
public string NavalDepartment { get; set; }
public string MiscellaneousInfo { get; set; }
public EmergencyType EmergencyType { get; set; }
public WarningType WarningType { get; set; }
public DateTime IssuedDate { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string WarningMessage { get; set; }
public string WarningInfo { get; set; }
public bool Active { get; set; }
public string Status { get; set; }
}
这就是我的仓库
public class WarningRepository :IWarningRepository
{
private ApplicationDbContext _context { get; set; }
public WarningRepository (ApplicationDbContext context)
{
_context = context;
}
}
我想groupby
警告上startDate.Year
(这是active == true
)并连接其列WarningYearCounter
(类似于MySQL中的group_concat
)像这样
Year Warning
2014 1,5,6,7
2015 6,8,9,0
查询:
_context.Warnings.Where(w => w.Active == true).GroupBy(w => w.StartDate.Year)
什么阻止你添加它? – kiziu
那么你提供的查询有什么错误? – decPL
@kiziu我不知道如何连接列linq到实体 –