我遇到了无法将列表分组的问题,我进行了研究并尝试了不同的方法,但结果不是我想要的。我不确定我是否做错了什么。
List<NewSomeGroup> newsomegourplist = new List<NewSomeGroup>();
var query = from c in _someRepository.Table
where c.isRead == false
group c by c.ReferenceId into grpdlist
orderby grpdlist.Key
select grpdlist;
foreach (var grpdlist in query)
{
NewSomeGroup somegroup = new NewSomeGroup();
List<Some> somelist = new List<Some>();
somegroup.ReferenceId = grpdlist.Key;
foreach (var item in grpdlist) // not in
{
somelist.Add(item);
}
somegroup.somecontainlist = somelist;
newsomegourplist.Add(somegroup);
}
最后somegroup有正确ReferenceId但somecontainlist有空的对象。我很确定它在数据库中有数据,我也尝试在 localhost 中调试,发现它//not in没有添加item.
数据结构
public class NewSomeGroup
{
public string ReferenceId { get; set; }
public List<Some> sbnotificationlist { get; set; }
}
public class Some
{
public string Title { get; set; }
public string projectid { get; set; }
public SimpleAccountInfo AccountInfo { get; set; }
public string Type { get; set; }
public string ReferenceId { get; set; }
public string iconPath { get; set; }
public DateTime CreateOnUtc { get; set; }
}
狐的传说
茅侃侃
相关分类