异常详细信息:System.NotSupportedException:LINQ to Entities中仅支持无参数构造函数和初始值设定项

时间:2016-02-22 06:47:18

标签: linq linq-to-entities

当我尝试运行此代码时,此异常“在LINQ to Entities中仅支持无参数构造函数和初始化”。被扔了。你可以帮我解决这个问题。

        var year = DateTime.Now.AddMinutes(318).Year;
        var month = DateTime.Now.AddMinutes(318).Month;
        var start = new DateTime();
        if (month >= 4)
        {
            start = new DateTime(year, 04, 01);
        }
        else if (month < 4)
        {
            start = new DateTime(year - 1, 04, 01);
        }
        var qr =  (from h in context.heads
                  join l in context.ledgers.Where(x => x.entry_date >= start && x.entry_date < new DateTime(year, month, 1))
                  on h.h_id equals l.h_id into hl where hl.Any()
                  let totalbalance = hl.Sum(d => d.debit) - hl.Sum(c => c.credit)
                  select new { h.name, totalbalance });
        Repeater2.DataSource = qr.OrderByDescending(x => x.totalbalance).Take(4);
        Repeater2.DataBind();

0 个答案:

没有答案