How do I find all posts that match a given criteria


T

Tony Johansson

In the database I have a string containing this format YYYY-MM-DD hh:mm:ss
As an example it could be 2014-06-15 22:12:04
The column name is CreatedDate

Now I want to find all posts that match a given year for example 2014 by
using Linq or lambda expression.

How can I write that ?

//Tony
 
Ad

Advertisements

A

Arne Vajhøj

In the database I have a string containing this format YYYY-MM-DD hh:mm:ss
As an example it could be 2014-06-15 22:12:04
The column name is CreatedDate

Now I want to find all posts that match a given year for example 2014 by
using Linq or lambda expression.

How can I write that ?

If you use plain SQL to load the data then you can use a WHERE condition
to limit years.

If you use an ORM to load data then you may need to load data into
memory and then you can use LINQ to objects to select the data.

Arne
 
Ad

Advertisements

B

bradbury9

El martes, 17 de junio de 2014 04:19:52 UTC+2, Arne Vajhøj escribió:
If you use plain SQL to load the data then you can use a WHERE condition

to limit years.



If you use an ORM to load data then you may need to load data into

memory and then you can use LINQ to objects to select the data.



Arne

Sample using Ling to objects and datacontexts.
As a side note, CreatedDate should have been datetime to ensure no wrong data is inserted in the table.

// bd is the datacontext
List<Post> results = (from reg in bd.posts where reg.CreatedDate.StartsWith("2014-") select reg).ToList();
 

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

Top