Solved

Linq Query Question: Chart Dataset

Posted on 2012-03-28
2
316 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:agarwalrahul
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net repeater server posting 5 39
Subtract dates in vb.net 6 35
Queries: Select, then Append, then Delete 8 41
What does "Between" mean? 6 48
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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