Use Multiple Column Group by in LINQ

We want to use Multiple Column Group by in LINQ.How to use this please help me.
Last updated:3/25/2016 11:24:03 PM

1 Answers

Aditya Patel
Aditya Patel

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace ForumMVC.Controllers{

public class HomeController : Controller

{

forumEntities context = new forumEntities();

public ActionResult Index()

{

var result = from c in context.CUSTOMER.ToList()

group c by new

{

c.CUST_NAME,

c.CUST_ADDRESS,

c.CUST_PHONE,

} into gcs

select new CUSTOMER()

{

CUST_NAME = gcs.Key.CUST_NAME,

CUST_ADDRESS = gcs.Key.CUST_ADDRESS,

CUST_PHONE = gcs.Key.CUST_PHONE,

};

return View();

}

}

}

Answer