user390480
user390480

Reputation: 1665

Add minutes from one column to datetime column in linq query

I have a column in my database named Created which is a datetime and a column named Minutes which is a varchar(5) and will contains values such as 0, 60, 120, etc.

How can I write a LINQ statment that only returns those records:

where Created + Minutes has gone passed the current time?

Thank you!

--- Update: code so far ---

var results = from emails in MyDAL.Context.Emails
   emails.Created.Value.AddMinutes(double.Parse(emails.Minutes)) > DateTime.Now
   select emails;

Upvotes: 1

Views: 2045

Answers (2)

user390480
user390480

Reputation: 1665

For others looking for the answer, here is how I ended up making it work....

System.Data.Objects.EntityFunctions.AddMinutes(emails.Created, emails.Minutes) < DateTime.Now

Upvotes: 2

Jon Skeet
Jon Skeet

Reputation: 1501163

Well you could try:

DateTime now = DateTime.UtcNow;

var query = from record in db.Records
            where record.Create.AddMinutes(int.Parse(record.Minutes)) > now
            select record;

Whether that will work or not depends on the LINQ provider...

Upvotes: 1

Related Questions