Click here to Skip to main content
15,889,505 members
Home / Discussions / C#
   

C#

 
QuestionRequesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa1-May-12 20:48
Nadia Monalisa1-May-12 20:48 
Hi,

In my code, I am counting the number of records (sent emails) that are older than one month. In order to do that, I am using following snippet.

C#
int totalSentEmailsOlderThanMonth = emailSendingService.ListSentEmails().ToArray().Count(x => (DateTime.Now - x.SentDateTime).TotalDays > 30);


The reason I am using .ToArray() in my code as (DateTime.Now - x.SentDateTime).TotalDays cannot be translated in LINQ to SQL query so, by calling ToArray(), I am loading all records into the memory and then counting. But there are more than hundreds of records in my database and loading all the records into the memory just for counting is not efficient at all. So, would anyone please give me an alternative more efficient snippet that can be used in this scenario.

[[ By the way, emailSendingService.ListSentEmails() returns IQueryable<MyRecordType> ]]

Regards.
AnswerRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Keith Barrow2-May-12 2:23
professionalKeith Barrow2-May-12 2:23 
GeneralRe: Requesting for a snippet that can be used in LINQ to SQL query Pin
Nadia Monalisa2-May-12 4:32
Nadia Monalisa2-May-12 4:32 
QuestionSIFT Pin
ri19871-May-12 20:05
ri19871-May-12 20:05 
AnswerRe: SIFT Pin
AmbiguousName1-May-12 20:09
AmbiguousName1-May-12 20:09 
AnswerRe: SIFT Pin
egenis1-May-12 20:09
egenis1-May-12 20:09 
AnswerRe: SIFT Pin
Abhinav S1-May-12 20:27
Abhinav S1-May-12 20:27 
GeneralRe: SIFT Pin
ri19871-May-12 21:48
ri19871-May-12 21:48 
GeneralRe: SIFT Pin
ri19872-May-12 21:13
ri19872-May-12 21:13 
GeneralRe: SIFT Pin
ri19872-May-12 21:16
ri19872-May-12 21:16 
JokeRe: SIFT Pin
PIEBALDconsult2-May-12 11:05
mvePIEBALDconsult2-May-12 11:05 
GeneralRe: SIFT Pin
Pete O'Hanlon2-May-12 11:32
mvePete O'Hanlon2-May-12 11:32 
GeneralRe: SIFT Pin
Member 1239536924-Apr-16 23:11
Member 1239536924-Apr-16 23:11 
QuestionHow to Override FileSystemInfo Class Readonly properties (Exists, Extension, Name, and etc)? Pin
ShadowUz1-May-12 19:34
ShadowUz1-May-12 19:34 
AnswerRe: How to Override FileSystemInfo Class Readonly properties (Exists, Extension, Name, and etc)? Pin
egenis1-May-12 20:05
egenis1-May-12 20:05 
QuestionShowingTabs After Authentication Pin
AmbiguousName1-May-12 19:03
AmbiguousName1-May-12 19:03 
AnswerRe: ShowingTabs After Authentication Pin
Eddy Vluggen2-May-12 0:02
professionalEddy Vluggen2-May-12 0:02 
Questionembed javascript code in c# Pin
mrx1001-May-12 12:02
mrx1001-May-12 12:02 
AnswerRe: embed javascript code in c# Pin
Dave Kreskowiak1-May-12 13:27
mveDave Kreskowiak1-May-12 13:27 
AnswerRe: embed javascript code in c# Pin
Abhinav S1-May-12 16:36
Abhinav S1-May-12 16:36 
Questionhow can i add a midi file in my csharp project? Pin
SeyedRezaFatemi1-May-12 10:20
SeyedRezaFatemi1-May-12 10:20 
AnswerRe: how can i add a midi file in my csharp project? Pin
Richard MacCutchan1-May-12 10:41
mveRichard MacCutchan1-May-12 10:41 
AnswerRe: how can i add a midi file in my csharp project? Pin
egenis1-May-12 20:28
egenis1-May-12 20:28 
QuestionHow can i specify drive specification Pin
Fred 341-May-12 9:11
Fred 341-May-12 9:11 
JokeRe: How can i specify drive specification PinPopular
Wes Aday1-May-12 9:42
professionalWes Aday1-May-12 9:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.