linq query group by
-
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
-
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
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 -
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 Templatesthanx.. 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
-
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
-
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
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 -
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
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.
-
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
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