Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2037 |  Welcome, Guest!   Register  Login
 Home > Blogs > LINQ > Group By in Linq ...
Ajay.Kalol

Group By in Linq

 Blog author: Ajay.Kalol | Posted on: 6/2/2012 | Category: LINQ Blogs | Views: 745 | Status: [Member] | Points: 75 | Alert Moderator   



Group by Operation in Linq.

 List<string> ls = new List<string>();

   using (LinqModel.LinqEntities ST1 = new LinqModel.LinqEntities())
   {
       var V = (from State in ST1.State_Master
                    group State by State.CountryID into temp
                    select new
                         {
                             T1 = temp.Key.Value,
                             T2 = temp
                         }).ToList();
               
                foreach (var c in V)
                {
                    for (int i = 0; i < c.T2.ToList().Count; i++)
                    {
                        ls.Add(c.T2.ToList()[i].StateName);
                    }
                }

   };

   // Group by With Linq using Lambada expression
   // Same Result as above
  
   using (LinqModel.LinqEntities ST1 = new LinqModel.LinqEntities())
   {
    var vLambada = ST.State_Master.GroupBy(state => state.CountryID).ToList();
  
          foreach (var state in vLambada)
            {
                for (int i = 0; i < state.Count(); i++)
                {
                    ls.Add(state.ToList()[i].StateName);
                }
            }
    };
            Rpt.DataSource = ls;
            Rpt.DataBind();



http://ajaypatelfromsanthal.blogspot.in
Found interesting? Add this to:



 More Blogs from Ajay.Kalol

     More ...

    About Ajay Patel

    Experience:1 year(s)
    Home page:http://ajaypatelfromsanthal.blogspot.in/
    Member since:Thursday, April 05, 2012
    Level:Starter
    Status: [Member]
    Biography:
    >> Write Response - Respond to this post and get points

    More Blogs

    About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
    General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
    Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/18/2013 9:45:20 PM