Entity framework with linq in asp.net mvc 5

asp.net-mvc-5 entity-framework entity-framework-6 linq linq-to-sql

Question

I am using linq query to group by element through one table field, guid.

The problem is that I do not know how to retrieve the object on the view.

Here is my code:

public ActionResult Index2()
{
    List<Imageupload> lists = db.Imageuploads.ToList();
    var a = lists.GroupBy(g => g.guid);

    return View(a);
}

Imageupload is a modal class and Imageuploads is a table in the database.

How can I accomplish that?

1
1
9/13/2018 12:26:11 AM

Popular Answer

Try this:

var groupedList = db.Imageuploads
    .GroupBy(u => u.guid)
    .Select(g=> g.ToList())
    .ToList();

Hope this helps

0
9/12/2018 4:49:39 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow