ADO.NET :: Group By Date In Linq?
Mar 28, 2011
I've a table with datetime null field in sql server. I'm trying to group the results based on the year in that field. But, when I wrote linq query, I didn't get intellisense for Year when I type that field. It only shows HasValue and Value. I think because it is converted nullable type. How do I do the grouping in this case?
View 5 Replies
Similar Messages:
Mar 26, 2010
I'm using a linq group by query (with two grouping parameters) and would like to use the resulting data in a nested repeater.
var dateGroups = from row in data.AsEnumerable()
group row by new { StartDate = row["StartDate"], EndDate = row["EndDate"] };
"data" is a DataTable from an SqlDataAdapter-filled DataSet. "dateGroups" is used in the parent repeater, and I can access the group keys using Eval("key.StartDate") and Eval("key.EndDate").
Since dateGroups actually contains all the data rows grouped neatly by Start/End date, I'd like to access those rows to display the data in a child repeater. To what would I set the child repeater's DataSource? I have tried every expression in markup I could think of; I think the problem is that I'm trying to access an anonymous member (and I don't know how.) In case it doesn't turn out to be obvious, what would be the expression to access the elements in each iteration of the child repeater? Is there an expression that would let me set the DataSource in the markup, or will it have to be in the codebehind on some event in the parent repeater?
View 3 Replies
Jan 27, 2011
I have the following:
[code]....
I keep getting this error:
Message = "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."
What i'm trying to do is group by ContentObjectId and then get StartDate that is greater than today.
I'm using entity framwork and MS SQL2008
View 2 Replies
Jan 25, 2011
I want to create a LINQ SQL-Group-Query... This is my LINQ-Query:
[Code]....
I want to Group this, like this normal SQL-Query do it?
[Code]....
Furtermore, when iam using this normal sql query the programm needs a Type .. for example Dim reqdata(of Iqueryable(of xxx)("sql query...") ... whats the Type of this ? When i select more tables than ones ? there is said thats <anonymous type> ?
View 1 Replies
Jun 25, 2010
I am trying to translate this:
SELECT IDNum, Max(Convert(varchar(20), (TimeOut - TimeIn), 108))
FROM IO_Times Group by IDNum
order by Max(Convert(varchar(20), (TimeOut - TimeIn), 108)) desc";
Into LINQ in C#. The above returns a list of the maximum value of (TimeOut-TimeIn) that corresponds to each unique IDNum (There are multiple TimeOut-TimeIn values for every IDNum).Here is what I am trying now:
from IO_Time in db.IO_Times
orderby SqlMethods.DateDiffMinute(IO_Time.TimeIn, IO_Time.TimeOut) descending
group IO_Time by IO_Time.IDNum into list
select new
{
ID = list.Key,
Time = list
});
This returns the correct IDs in the correct order, but the "list" contains everything in the database entry (which makes sense). I have also tried group by IDNum and Time, but then I get unique time entries and multiple IDs returned.I could do a foreach loop and manually sort it all out, but I would really rather not do that.
View 2 Replies
Dec 9, 2010
I have T_articles to save the articles.
each article has authorCode , and categoryCode.
each article can be modified by the author several times.
and I save every modification in the T_articles in a difference row.
now I want to dislpay for each autor:
author name, article name , article category's name, last modified date
In SQL I should to it like that:
[Code]....
I try to write it in Linq so:
[Code]....
so I got error:
[Code]....
and again I got an error:
[Code]....
View 4 Replies
Aug 8, 2010
Using Linq to Sql how do i group the following 2 tables.
Orders Table:
CustomerID | Name |Date
1 | order1 | 2010-01-01
2 | order2 | 2010-01-01
2 | order3 | 2010-04-01
Calls Table:
CustomerID | Name |Date
1 | call1 | 2010-01-01
3 | call2 | 2010-06-01
2 | call3 | 2010-05-01
I want to group the two tables by date , Result:
Date | Orders | Calls
2010-01-01 | 2 | 1
2010-04-01 | 1 | 0
2010-05-01 | 0 | 1
2010-06-01 | 0 | 1
i know how to group a single table ,from o in Orders group o by o.Date.Date into og select new {Date = og.Key,Orders= og.Count()};
View 2 Replies
Mar 18, 2011
How to search between start date and end date using LINQ to Entity?
dear i m working on project and i want to search record by using start date and end date from the Table name of task so kindle solve my problem
View 9 Replies
Sep 9, 2010
I have this group-join syntax but I couldn't get the distinct value from the relational tables below.
Table_1
key_1 t1_value
1 Food
2 Sports
3 Leisure
4 Trip
5 Zoo
Table_2
key_2 key_1 t2_boolean
15 1 True
16 1 True
17 1 True
18 2 True
19 2 True
20 2 False
desire result:
[code]...
View 3 Replies
Sep 30, 2010
I am wonder how I can generate a result table from linq to sql as below
Car sales table
Toyota small
Toyota passenger
Toyota small
Honda small
Honda small
Honda passenger
Honda small
result table
Brand small passenger total
Toyata 2 1 3
Honda 3 1 4
GridView1.DataSource = (from dtCarSales.AsEnumerable() .....
View 3 Replies
Feb 8, 2010
I'm attempting to further reduce a dataset/table by various user input. Part of this process is grouping the data by a timestamp prior to a summation. I'm trying to use LINQ and cannot get the data returned that I need.
[Code]....
View 7 Replies
Mar 14, 2010
How do I translate the following query into LINQ to SQL?
[Code]....
View 1 Replies
Feb 11, 2010
I have createdate field in a table and I want to use that field to group items in a gridview based on the date. For instance, if the datediff is less than 25 hours ago then I want to show the word "Today" or if greater than 24 but less than 48 hours show the word "Yesterday" etc.
View 6 Replies
Oct 25, 2010
1
down vote
favorite
1
View 2 Replies
Jan 8, 2010
i have the following objects:
Event:
- EventID (PK)
- GroupID (FK)
- StartDate
Group:
- GroupID (PK)
- GroupName
What i need to do is select the last 5 events for each group using LINQ to Objects. I tried starting with:
[Code]....
But i'm not sure how i only take the last 5 per group.
The simple way of doing this is to get the groups and then have a property on that which returns the last 5 events but if i databind this i will have to use a nested Repeater/ListView. Ideally i would like to have a row foreach event.
View 3 Replies
Jan 26, 2011
i have a data driven web application, in my database i have this datetime column,
and in my web application i have this gridview, but the only data that i need to display are the records with todays date until the past 6 days from today, so its like 7 days all in all.
View 4 Replies
Aug 21, 2010
I have a table containing courses, columns are
Name - "Yoga Classes"
DateStart - "2/23/2010"
DateEnd - "2/24/2010"
I am using ListView Control to bind it, is there a way to display them and group them by Month? for eg.
January
Piano Class (10th Jan 2010 - 11th Jan 2010)
Guitar Class (10th Jan 2010 - 11th Jan 2010)
February
Yoga Class (15th Feb 2010 - 16th Feb 2010)
etc...
View 5 Replies
Jan 27, 2011
This group section cannot be printed because its condition field is nonexistent or invalid. Format the section to choose another condition field. Error in File Detailed_CrystalReport {9C8154B9-5093-457C-9E6A-2A1D63E7E866}.rpt: Invalid group condition.
without group section report can correctly show report and with group section can correctly show in local computer only with visual studio But with group section has error after deploy to new machine window server 2008 group section is date my crystal report version is 2008, assembly version 12, CRDist x64
try 1: i try to delete the group date and run local, it can correctly show date, but deploy to the new machine date is invisible Group date is wrong the date have only 01/25/2011 however group date become 23/1/2011 why group date is not 01/25/2011?
View 1 Replies
Mar 24, 2011
I'm trying to build a linq2Entity/gridview function for a forum, that draws data from multible tables.The result should be: Get the latest 10 threads that user(xx) has replyed in, that is not disabled or has a subject that is not allowed.Include information on the last post, thread owner user, and last post user, in each thread.
ere is my code... is returns the correct threads and some that should not be there.
[Code]....
View 1 Replies
Sep 3, 2010
How to do in LINQ? And below is correct or not if put string.format in LINQ?
[code]....
View 8 Replies
Mar 4, 2010
Stack-Overflow :3 I've got a kind of hard-case question.
So I'll try clearly explain my idea with my poor english :/ need select to DataTable SOME values from ???_**GetDisplayData **procedure for each day of previos month (GROUP IT) where group rules for different columns is different
I need to select some values in stored procedure from other stored procedure like this :
SELECT X FROM Y_Procedure(@ProcedureParameters)Also I need to select from dynamic SQL Procedure like
Y_Procedure=@Y+'_Procedure'
SELECT X FROM Y_Procedure(@ProcedureParameters)
Also I need to load it to DataTable :-/INSERT INTO @Report (CellHorizontal, CellVertical, CellValue) --to TABLE
SELECT Date,X2,X3 FROM Y_GetDisplayData(@Param)
SET NOCOUNT OFF;
SELECT *
FROM @Report
GetDisplayData works as select with parameters and that doesn't returns SQL DataTable
And there is no way to recode GetDisplayData's procedures, it's just constant procedures for me.Finally I need to Group nodes from this table
INSERT INTO @Report (CellHorizontal, CellVertical, CellValue)
SELECT T1.Date,
IF ((Select grouptype...)=1) T1.X2 + T2.X2
ELSE IF ((Select grouptype...)=2) AVG(T1.X2,T2.X2),
IF ((Select grouptype...)=1) T1.X3 + T2.X3
ELSE IF ((Select grouptype...)=2) AVG(T1.X3,T2.X3),
(SELECT T2.Date,X2,X3 FROM Y_GetDisplayData(@Param) T2
WHERE T2.Date>T1.Date AND T2.Date>=T1.Date)
FROM Y_GetDisplayData(@Param) T1
GROUP BY EVERY DAY ???--and here is epic fail
I can make all stuff on asp server :And C# allows me to use something like SelectCommand = IzmProc + "_GetDisplayData"; And then I will work (select special data) with DataTables on ASP.NET Server but it's better to make all on SQL ... But looking like it's just unrealizable on SQL >_<
I gonna think about C# realization,but my code is very weird , got errors and doesn't works >_<
public static DataTable GetReport(string Param)
{
System.Configuration.ConnectionStringSettings connSetting = ConfigurationManager.ConnectionStrings["FlowServerConnectionString"]; [code].....
View 3 Replies
Aug 2, 2010
I have problem in converting date to string I am using cstr(p.tripstart) , which is returning Date as 12 Aug 2010 12:AM I need to make formating This is my code :
[Code]....
View 9 Replies
Dec 7, 2010
I am trying to query my datatable for part of 2010 and part of 2011. My datatable returns records if I query 01/01/2010 to 12/31/2010. It fails and returns no records if I query any date in 2011. my 'txt..selecteddate' is a telerik control but that is not the problem. Imagine it as just a textbox or something
[Code]....
View 1 Replies
Nov 23, 2010
Post table
int_PostId int Unchecked
int_TemplateId int Checked
int_OrganizationId int Checked
int_SortOrder int Checked
int_PostTypeId int Checked
int_PostStatusId int Checked
int_Hits bigint Checked
int_CreatedBy int Checked
dtm_CreatedDate datetime Checked
int_ModifiedBy int Checked
dtm_ModifiedDate datetime Checked
29
1
23
1
2
4
NULL
41
2010-09-09 12:24:38.970
41
2010-09-09 12:26:50.063
30
1
23
1
2
4
NULL
41
2010-09-09 12:27:22.817
NULL
NULL
31
1
23
1
1
3
NULL
41
2010-09-09 12:51:17.933
NULL
NULL
32
1
23
NULL
1
3
NULL
41
2010-09-09 12:58:32.650
NULL
NULL
33
1
23
1
2
3
NULL
41
2010-09-09 13:23:51.757
NULL
NULL
34
1
23
1
2
3
NULL
41
2010-09-09 13:24:34.517
NULL
NULL
35
1
26
1
2
3
NULL
41
2010-09-14 17:34:35.517
41
2010-09-14 17:37:41.857
36
1
26
145
2
5
NULL
41
2010-09-14 17:43:04.423
41
2010-09-14 17:44:40.167
Post Meta Table
int_MetaId int Unchecked
vcr_MetaKey nvarchar(200) Checked
vcr_MetaValue nvarchar(200) Checked
int_PostId int Checked
bit_IsPostType bit Checked
int_CreatedBy int Checked
dtm_CreatedDate datetime Checked
int_ModifiedBy int Checked
dtm_ModifiedDate datetime Checked
57
chkEng
true
6
NULL
36
2010-10-12 07:59:05.357
NULL
NULL
58
chkdar
false
6
NULL
36
2010-10-12 07:59:05.357
NULL
NULL
59
chkpsh
false
6
NULL
36
2010-10-12 07:59:05.357
NULL
NULL
60
Publish Date
08/22/2010
6
True
42
2010-10-12 07:59:05.357
NULL
NULL
61
Thumbnail Image
6
True
42
2010-10-12 07:59:05.357
NULL
NULL
62
Featured Image
6
True
42
2010-10-12 07:59:05.357
NULL
NULL
63
Source
6
True
42
2010-10-12 07:59:05.357
NULL
NULL
71
chkEng
true
8
NULL
42
2010-10-12 08:01:26.900
NULL
NULL
72
chkdar
false
8
NULL
42
2010-10-12 08:01:26.900
NULL
NULL
73
chkpsh
false
8
NULL
42
2010-10-12 08:01:26.900
NULL
NULL
74
Publish Date
08/22/2010
8
True
42
2010-10-12 08:01:26.900
NULL
NULL
75
Source
8
True
42
2010-10-12 08:01:26.900
NULL
NULL
76
Thumbnail Image
8
True
42
2010-10-12 08:01:26.900
NULL
NULL
77
Featured Image
8
True
42
2010-10-12 08:01:26.900
NULL
NULL
78
chkEng
true
7
NULL
43
2010-10-12 08:02:08.417
NULL
NULL
79
chkdar
false
7
NULL
43
2010-10-12 08:02:08.417
NULL
NULL
80
chkpsh
false
7
NULL
43
2010-10-12 08:02:08.417
NULL
NULL
81
Publish Date
7
True
43
2010-10-12 08:02:08.417
NULL
NULL
i included the table and its data as it would be impossible without that to understand. this is the meta scenario as you may notice that this was the query i wrote before when i was not checking the publish date
var postsidebar = from post in postrepository.GetAllPosts()
join pstmt in postrepository.GetAllPostMetas()
on post.int_PostId equals pstmt.int_PostId
where (post.int_PostTypeId == 4 && post.int_PostStatusId == 2 && post.int_OrganizationId == layoutrep.GetSidebarDetailById(SidebarDetailsId).int_OrganizationId)
&& (pstmt.vcr_MetaKey.Contains(filter) && pstmt.vcr_MetaValue.Contains("true"))
select post
how would i goint incoperate check for publish date in the query above( i want to bring all the records whose publish date is greater then todays date)
View 1 Replies
Mar 14, 2011
I have a simple If..Then like so:
If rhcexists.First.SignatureDate > Date.Today.AddMonths(-6) Then
End If
rhcexists is a simple query to the Entity Model:
Dim rhcexists = From p In dbContracts.Signatures _
Where p.StudentID = CStr(Session("people_code_id")) _
And p.ContractType = "rhc" _
Order By p.ID Descending _
Select p
Problem is that this comparison results in an error:
LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.
This is occurring on the If clause. Any ideas why this occurring and how I can fix it?
I am using ASP.NET 4, EF 4, and VS 2010 SP1.
View 1 Replies