Solved

Linq Query Question: Chart Dataset

Posted on 2012-03-28
2
303 Views
Last Modified: 2012-03-29
Let's say we have this table...

Table: PARTS
ID     PartName      DateTimeCreated
1       Hammer         7/1/2012 01:22:33
2       Shovel             7/1/2012 01:22:33      
3       Nail                 7/2/2012 01:22:33
4       Wrench           7/3/2012 01:22:33
5       Screw              7/3/2012 01:22:33
6       Pliers              7/3/2012 01:22:33

and we need this dataset:

Dataset
Date                TotalPartsCreatedDuringDate
7/1/2012         2
7/2/2012         1
7/3/2012         3

How would be build a linq query to get this?
0
Comment
Question by:adskarcox
2 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
Comment Utility
var q = from i in ABD.Listitem
        let dt = p.EffectiveDate
        group i by new { y = dt.Year, m = dt.Month, d = dt.Day}
        select g;

Reference:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/cb58ae5f-5db9-4054-92b6-a1bf63764574
0
 
LVL 10

Accepted Solution

by:
eguilherme earned 500 total points
Comment Utility
check this:

var TotalByDate = (from t in Part.getSamples()
		   group t by t.DateTimeCreated.Date into n
		   select new
		   {
			   Date = n.Key.Date,
			   TotalPartsCreatedDuringDate = n.Count()
		   }).ToList();

Open in new window


and the getSamples method used for this test

public class Part
{
	public int ID {get;set;}
	public string PartName {get;set;}
	public DateTime DateTimeCreated {get;set;}

	public static List<Part> getSamples()
	{
		return new List<Part>()
		{
			new Part() { PartName = "Hammer", ID = 1, DateTimeCreated = new DateTime(2012,1,7,01,22,33) },
			new Part() { PartName = "Shovel", ID = 2, DateTimeCreated = new DateTime(2012,1,7,01,22,33) },
			new Part() { PartName = "Nail", ID = 3, DateTimeCreated = new DateTime(2012,2,7,01,22,33) },
			new Part() { PartName = "Wrench", ID = 4, DateTimeCreated = new DateTime(2012,3,7,01,22,33) },
			new Part() { PartName = "Screw", ID = 5, DateTimeCreated = new DateTime(2012,3,7,01,22,33) },
			new Part() { PartName = "Pliers", ID = 6, DateTimeCreated = new DateTime(2012,3,7,01,22,33) }
		};
	}
}

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now