C# 如何从使用linq查询读取的数据集中计算表中的总计数
下面是我的查询,根据某些条件,我使用Linq连接了几个表C# 如何从使用linq查询读取的数据集中计算表中的总计数,c#,sql,sql-server,linq,datatable,C#,Sql,Sql Server,Linq,Datatable,下面是我的查询,根据某些条件,我使用Linq连接了几个表 var Info = from tblcol1 in Table1 join tblcol2 in dc.Table2 on tblcol1.EmailID equals tblcol2.EmailID join tblcol3 in dc.Table3 on tblcol1.EmailID equals tblcol3.EmailID join tblcol4 in dc
var Info = from tblcol1 in Table1
join tblcol2 in dc.Table2 on tblcol1.EmailID equals tblcol2.EmailID
join tblcol3 in dc.Table3 on tblcol1.EmailID equals tblcol3.EmailID
join tblcol4 in dc.Table4 on tblcol3.GroupID equals tblcol4.GroupID
join tblcol5 in dc.Table5 on tblcol4.RID equals tblcol5.RID
join tblcol6 in dc.Table6 on tblcol2.RID equals tblcol6.RID
join tblcol7 in dc.Table7 on tblcol1.EmailID equals tblcol7.EmailID
where tblcol1.UserId.Equals(gUserID)
select new Class1()
{
EmailID = tblcol1.EmailID.ToString(),
EmailName = tblcol1.Name.ToString(),
OpenCount = tblcol7.OpenCount,
ReadCount = tblcol7.ReadCount,
TotalCount = tblcol5.RID + tblcol6.RID,
UnsubscribeCount = tblcol6.IsUnsubscribed + tblcol5.IsUnsubscribed,
};
List = Info.ToList();
其中RID是GUID(C#)/唯一标识符(SQL),IsUnsubscribed是SQL数据表中的位
我需要在上面的查询中计算TotalCount和UnsubscribedCount
TotalCount = tblcol5.RID + tblcol6.RID,
UnsubscribeCount = tblcol6.IsUnsubscribed + tblcol5.IsUnsubscribed,
我如何做到这一点呢?您是否只是在查看计数?如果是这样,您是否尝试过
var totalUnsubscribeCount=Info.Sum(=>uu.UnsubscribeCount)代码>?您真的想在TotalCount=tblcol5.RID+tblcol6.RID行上添加两个GUID吗。@DarylBehrens我不想添加GUID。。。我忘了提到我想要添加那些GUID正在发生的计数数…我需要使用class1对象本身内部的select new class1()语句创建的每个对象的IsUnscribed计数。