Solved

Linq Query Question: Chart Dataset

Posted on 2012-03-28
2
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Expert Comment

by:Rahul Agarwal
ID: 37780371
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
ID: 37781273
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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