读书人

linq源码改错!解决思路

发布时间: 2013-08-04 18:26:16 作者: rapoo

linq源码改错!!!
这个对应我的另一个帖子中提到的较复杂的功能的代码;用的自己的思路写的,第一次碰C#,劳烦各位版主原谅我的各种低级错误阿

var reportQuery = from a in examReportTable.AsEnumerable()
join b in rvuTable.AsEnumerable()
on new{exam=a.Field<string>("exam"), examtype=a.Field<string>("examtype")} equals new{rvuName=b.Field<string>("rvuName"), rvuType=b.Field<string>("rvuType")}
group b by new{ reportDoc=a.Field<string>("reportDoc"),examtype=a.Field<string>("examtype") } into c
select new
{
DocName = c.Field<string>("reportDoc"),
examType = c.Field<string>("type"),
reportDocRvu = c.Field<double>.Sum(o=>o.reportRvu),
reportDocNum = c.Field<double>.count(o=>o.reportRvu)
};


var auditQuery = from aa in examAuditTable.AsEnumerable()
join bb in rvuTable.AsEnumerable()
on new{exam=aa.Field<string>("exam"),examtype=aa.Field<string>("examtype")} equals new{rvuName=bb.Field<string>("rvuName"),rvuType=bb.Field<string>("rvuType")}


group bb by new{aa.auditDoc,aa.examtype} into cc
select new
{
DocName = cc.reportDoc,
examType = cc.type,
auditDocRvu = cc.Sum(o=>o.auditRvu),
auditDocNum = cc.Count(o=>o.auditRvu)
};

private DataTable workloadTable;
workloadTable.Columns.Add("docName",typeof(string));
workloadTable.Columns.Add("type",typeof(string));
workloadTable.Columns.Add("reportDocRvu", typeof(double));
workloadTable.Columns.Add ("reportDocNum",typeof(double));
workloadTable.Columns.Add ("auditDocRvu",typeof(double));
workloadTable.Columns.Add ("auditDocNum",typeof(double));

foreach (var q in reportQuery )
{
workloadTable.Rows.Add(q.DocName, q.examType,q.reportDocRvu,q.reportDocNum,0,0);
}
foreach (var q in auditQuery)
{
workloadTable.Rows.Add(q.DocName, q.examType, 0,0,q.auditDocRvu, q.auditDocNum);
}

var rvuQuery = from a in workloadTable.AsEnumerable()
group a by new {docName=a.Field<string>("docName"),type=a.Field<string>("type") }into g


select new
{
DocName = g.docName,
examType = g.type,
reportDocRVU = g.Sum(o=>o.reportDocRvu),
reportDocNum = g.Sum(o=>o.reportDocNum),
auditDocRVU = g.Sum(o=>o.auditDocRvu),
auditDocNum = g.Sum(o=>o.auditDocNum)
}; LINQ 源代码 join select
[解决办法]

引用:
Quote: 引用:

我建议你分步去写linq查询,便于看每一步的结果。然后再组合在一起。

编译也通不过阿,比如:
第一段里提示我
join 子句中一个表达式的类型不正确。类型推理在对“Join”的调用中失败。
可我已经全部加上Field<string>了呀


on new{exam=a.Field<string>("exam"), examtype=a.Field<string>("examtype")} equals new{exam=b.Field<string>("rvuName"), examtype=b.Field<string>("rvuType")}



两个new里边的名称要保持一致

读书人网 >.NET

热点推荐