DateTime Range

S

shapper

Hello,

I have the following Linq query:

IQueryable<Article> articles = (from a in database.Articles
where a.IsPublished
== true
orderby a.UpdatedAt
descending).AsQueryable();

How can I get the articles which UpdatedAt is in a range of StartDate
to EndDate?

Thanks,
Miguel
 
P

Pavel Minaev

Hello,

I have the following Linq query:

      IQueryable<Article> articles = (from a in database.Articles
                                                   where a.IsPublished
== true
                                                   orderby a.UpdatedAt
descending).AsQueryable();

How can I get the articles which UpdatedAt is in a range of StartDate
to EndDate?

Normally you can use operators >= and <= with DateTime objects, so
"where a.UpdatedAt >= StartDate && a.UpdatedAt <= EndDate". This
should work for LINQ to Objects, but I've no idea if EF maps this to
SQL correctly or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top