那是我的實體模型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到實體 –