存在,还有其他方法可以计算这一点吗?
IList<DtoProfile> profileList = Session().QueryOver<DtoProfile>()
IList<Headword> methodList = Session().QueryOver<Headword>()
var hList = profileList.Select(x => x.HeadwordList).SelectMany(x => x).ToList();
profileList包含一个HeadwordList。现在hList包含类似
标题1:ID = 1,文本=文本1(来自配置文件1)
标题2:ID = 2,文本=文本2(来自配置文件1)
标题1 :ID = 1,文本=文本1(来自配置文件2)
methodList包含
标题1:ID = 1,文本= Text1
标题2:ID = 2,文本= Text2
标题2:ID = 3,文本= Text3
我想做一个字典像
键:Text1,值:2
键:Text2,值:1
键:Text3,值:0
var joined = (from headword in methodList
join profile in hList on headword equals profile
group headword by headword.Text
into groupedProfile
select groupedProfile).ToDictionary(x => x.Key, x => x.Count());
它行不通!我刚
键:Text1,值:2在我的词典中
,键:Text2,值:1
。现在我改进为左连接:
var joined = (from headword in methodList
join profile in hList on headword equals profile into ps
from profile in ps.DefaultIfEmpty()
group headword by headword.Text
into groupedProfile
select groupedProfile).ToDictionary(x => x.Key, x => x.Count(y => y != null));
但是y => y!= null不能正常工作!我得到:
键:Text1,值:2
键:Text2,值:1
键:Text3,值:1(错误,应为0)
我不确定我是否理解您的问题,但也许...
var joined = methodList
.ToDictionary(item => item.Text, item => hList.Count(h => h.Text == item.Text))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句