我已经在SO上看到了很多关于此错误的参考,但是我无法提出解决方案来解决我的问题。以我为例,我试图合并两个具有相似字段的不同表。下面是控制器动作
public IEnumerable Report(int? year, Guid? gcode)
{
DateTime startdate = (new DateTime(DateTime.Now.Year - 1, 7, 1));
DateTime enddate = (new DateTime(DateTime.Now.Year, 6, 30));
//get all online payments
var c = from of in db.OnlinePayments.Include(i => i.Customer).ToList()
select new { of.Customer, of.CustomerID, of.PDate, of.Pay, of.POK };
// get all offline payments
var b = from pa in db.OfflinePayments.Include(i => i.Customer).ToList()
select new { pa.Customer, pa.CustomerID, pa.PDate, pa.Pay,pa.POK };
var all = c.Concat(b);
var query =
(from bk in db.Customers.Where(a=>a.Active)
join tr in all.Where(x => x.PDate >= startdate && x.PDate <= enddate && x.POK && x.CustomerID!=2)
on bk.CustomerID equals tr.CustomerID into trs
select new CViewModel
{
Name = bk.FirstMiddleLastName,
custguid = bk.CustGuid.GetValueOrDefault(),
TotalPaid = (int?)trs.Sum(e => e.Pay) ?? 0
});
return query.AsEnumerable();
}
任何帮助将不胜感激。