Group and Join Linq statement wont pass to my view from controller

My View:

@model IEnumerable<TestingMainPage.Models.SummaryModel>

@if (Model.Count() > 1 )
{//Do something}
else
{//Do something else}

The error involved:

The model item passed into the dictionary is of type  'System.Data.Entity.Infrastructure.DbQuery`1[<>f__AnonymousType11`4[System.Int32,System.Nullable`1[System.DateTime],System.String,System.Nullable`1[System.Int32]]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[TestingMainPage.Models.SummaryModel]'.

Which is caused by the linq statement...

Can anybody tell me what is wrong with this linq statement? I am still new to linq and trying to figure it out..

For some reason I can run it in Linqer but it wont actually pass the model to my view in my project? Which I am assuming because there is something wrong with the Linq statement, because if I switch it up to a very simple select then it will pass the model..

        var BeginDate = DateTime.Now.AddDays(-5).ToString("d") + " 2:00:00";
        var EndDate = DateTime.Now.ToString("d") + " 2:00:00";
        DateTime Start = Convert.ToDateTime(BeginDate);
        DateTime End = Convert.ToDateTime(EndDate);

      var TestLinq = (from a in db.seqexp_master
                      join b in db.seqexp_detail on a.recid equals b.recid into b_join
                      from b in b_join.DefaultIfEmpty()
                      where
                        a.shipto == "1020" &&
                        (new string[] { "a", "c" }).Contains(a.status) &&
                        a.active == 1 &&
                        b.active == 1 &&
                        a.datetimestamp >= Start &&
                        a.datetimestamp <= End
                      group new { a, b } by new
                      {
                          a.recid,
                          a.datetimestamp,
                          a.status
                      } into g
                      orderby
                        g.Key.recid descending
                      select new
                      {
                          Recid = g.Key.recid,
                          datetimestamp = g.Key.datetimestamp,
                          status = g.Key.status,
                          Qty = g.Sum(p => p.b.qty)
                      });
return View(TestLinq);

Any help is appreciated :D Thanks

I dont think you would need to see my Model either, but just incase:

   public class SummaryModel
{
    public DateTime datetimestamp { get; set; }
    public char status { get; set; }
    public int? Recid { get; set; }
    public int? Qty { get; set; }
    public int? test { get; set; }
}
Jon Skeet
people
quotationmark

This is the problem, at the end of your query:

select new
{
    Recid = g.Key.recid,
    datetimestamp = g.Key.datetimestamp,
    status = g.Key.status,
    Qty = g.Sum(p => p.b.qty)
}

That's an anonymous type, but your view wants an IEnumerable<SummaryModel>. It's not clear what SummaryModel is, but perhaps you want:

select new SummaryModel
{
    Recid = g.Key.recid,
    datetimestamp = g.Key.datetimestamp,
    status = g.Key.status,
    Qty = g.Sum(p => p.b.qty)
}

(If so, I strongly recommend that you fix your property names to follow normal .NET conventions...)

people

See more on this question at Stackoverflow