分组
join t in total
on a.MetricPointID equals t.MetricPointID
into m
from n in m.DefaultIfEmpty()
select new
{
CategoryName = a.CategoryName,
CategoryID = a.CategoryID,
CategorySort = a.CategorySort,
DepartmentID = a.DepartmentID,
DepartmentsSort = a.DepartmentsSort,
MediumSort = a.MediumSort,
MediumID = a.MediumID,
Usage = a.Usage,
MetricPointID = a.MetricPointID,
TotalMonth = n.TotalMonth,
TotalYear = n.TotalYear,
AlertUsage = a.AlertUsage,
AlertTotalMonth = n.AlertTotalMonth,
AlertTotalYear = n.AlertTotalYear
}).ToList();
排序
var GcmisData = (from a in selector1 group a by a.GodCtgName into temp select new CaiWuEntities.GodCtgMoneyItem() { Name = temp.First().GodCtgName, Money = temp.Sum(b => b.Price * b.Count) }).ToArray();
左外连接
var final = (from a in alljoin t in total
on a.MetricPointID equals t.MetricPointID
into m
from n in m.DefaultIfEmpty()
select new
{
CategoryName = a.CategoryName,
CategoryID = a.CategoryID,
CategorySort = a.CategorySort,
DepartmentID = a.DepartmentID,
DepartmentsSort = a.DepartmentsSort,
MediumSort = a.MediumSort,
MediumID = a.MediumID,
Usage = a.Usage,
MetricPointID = a.MetricPointID,
TotalMonth = n.TotalMonth,
TotalYear = n.TotalYear,
AlertUsage = a.AlertUsage,
AlertTotalMonth = n.AlertTotalMonth,
AlertTotalYear = n.AlertTotalYear
}).ToList();
orderby a.ReqEndTime ?? DateTime.Parse("9999-12-31"), a.UpdateTime descending