Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. linq query group by

linq query group by

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqhelp
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    haseeb_saeed
    wrote on last edited by
    #1

    hi, i want to use the following query with in linq... select min(id),name from oemparts group by name please provide help best regards

    haseeb

    A A S W 4 Replies Last reply
    0
    • H haseeb_saeed

      hi, i want to use the following query with in linq... select min(id),name from oemparts group by name please provide help best regards

      haseeb

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      might be my article on Linq could help you... http://www.codeproject.com/KB/dotnet/LINQ.aspx Please take a look.:rose:

      Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
      Create .NET Templates

      H 1 Reply Last reply
      0
      • A Abhishek Sur

        might be my article on Linq could help you... http://www.codeproject.com/KB/dotnet/LINQ.aspx Please take a look.:rose:

        Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
        Create .NET Templates

        H Offline
        H Offline
        haseeb_saeed
        wrote on last edited by
        #3

        thanx.. was already using that, but had problems with selecting min(id), and name... i can select min(id) but the name was not being selected... Even did that now am having an exception var d = (from a in db.GetTable() group a by a.name into g select new { g.Min().id,g.Min().name }); foreach (var c in d) { dictMinIdPart.Add(c.id, c.name); } runtime exception: invalid operation exception Could not format node 'New' for execution as SQL. if i am mistaking in the query, pls correct me... if i am not mistakin..then why is this excption... i searched for exception and some sites call it a bug... i am not sure thanx for ur help

        haseeb

        S 1 Reply Last reply
        0
        • H haseeb_saeed

          thanx.. was already using that, but had problems with selecting min(id), and name... i can select min(id) but the name was not being selected... Even did that now am having an exception var d = (from a in db.GetTable() group a by a.name into g select new { g.Min().id,g.Min().name }); foreach (var c in d) { dictMinIdPart.Add(c.id, c.name); } runtime exception: invalid operation exception Could not format node 'New' for execution as SQL. if i am mistaking in the query, pls correct me... if i am not mistakin..then why is this excption... i searched for exception and some sites call it a bug... i am not sure thanx for ur help

          haseeb

          S Offline
          S Offline
          SayreCC
          wrote on last edited by
          #4

          Hi, try this Dim assns = (From a In dcdc.Registrations.ToList _ Group By a.Username Into ToList())

          Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.

          1 Reply Last reply
          0
          • H haseeb_saeed

            hi, i want to use the following query with in linq... select min(id),name from oemparts group by name please provide help best regards

            haseeb

            A Offline
            A Offline
            Andreas X
            wrote on last edited by
            #5

            Hello! try this:

            var result = from o in oemparts
            group o by o.name into g
            select new {Name = g.Key, MinID = g.Group.Min(o => o.ID)};

            int id = result.MinID;
            string name = result.Name;

            Andreas Johansson
            IT Professional at Office IT Partner i Norrbotten Sweden
            What we don't know. We learn.
            What you don't know. We teach

            1 Reply Last reply
            0
            • H haseeb_saeed

              hi, i want to use the following query with in linq... select min(id),name from oemparts group by name please provide help best regards

              haseeb

              S Offline
              S Offline
              SayreCC
              wrote on last edited by
              #6

              Hi, base on your example on how to group by in linq. if your using C# try my example: YOURDATACONTEXT DCDC = NEW YOURDATACONTEXT(); var q = from sai in DCDC.GetTable<YOURTABLENAME>(); group sai by sai.name into sayre                  select new { Name = sayre.name, }; textbox1.text   = q.Name;

              Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.

              1 Reply Last reply
              0
              • H haseeb_saeed

                hi, i want to use the following query with in linq... select min(id),name from oemparts group by name please provide help best regards

                haseeb

                W Offline
                W Offline
                Wimmo
                wrote on last edited by
                #7

                Here is a nice example of grouping using Linq

                public void Linq40() {
                int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

                        var numberGroups =
                            from n in numbers
                            group n by n % 5 into g
                            select new { Remainder = g.Key, Numbers = g };
                        
                        foreach (var g in numberGroups) {
                            Console.WriteLine("Numbers with a remainder of {0} when divided by 5:", g.Remainder);
                            foreach (var n in g.Numbers) {
                                Console.WriteLine(n);
                            }
                        }
                

                }

                more examples in C# you find : http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx[^] Hope this will help, Wim

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups