Home | Table Design |
GroupBy - Simple 1
This sample uses group by to partition a list of Item by their Order.
DataClassesDataContext db = new DataClassesDataContext();
LINQ:
var result = from oi in db.CustOrdeItems
group oi by oi.CustOID into ItemGroup
select new { ItemGroup.Key,Group = ItemGroup };
foreach (var item in result)
{
Response.Output.WriteLine("Key : {0}<br> ", item.Key);
foreach (var item2 in item.Group)
Response.Output.WriteLine(" Item : {0}<br> ", item2.Item);
}
Result:
Key : 1
Item : Colgate
Item : Grocery
Item : Shoes
Key : 2
Item : Plastic chair
Item : iron
Key : 3
Item : Bag
GroupBy - Simple 2
This sample uses group by to partition a list of words by their length.
DataClassesDataContext db = new DataClassesDataContext();
LINQ:
var result = from oi in db.CustOrdeItems
group oi by oi.Item.Length into ItemGroup
select new { ItemGroup.Key, Group = ItemGroup };
foreach (var oi in result)
{
Response.Output.WriteLine("Key : {0}<br> ", oi.Key);
foreach (var item in oi.Group)
Response.Output.WriteLine(" Item : {0}<br> ", item.Item);
}
Result:
Key : 3
Item : Bag
Key : 4
Item : iron
Key : 5
Item : Shoes
Key : 7
Item : Colgate
Item : Grocery
Key : 13
Item : Plastic chai
==============================
Shradhdha Zalavadiya |Senior Software Engineer
WebMingle Technology
Accelerated by knowledge. Driven by values.
www.webMingle.in
No comments:
Post a Comment