Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good day,

Can anyone assist me and try to help me on this following query and convert it to linq query?:-

FROM dbo.MyTable
WHERE myDate BETWEEN '2013-07-12 07:25' AND '2013-07-12 08:45'

because when I put it like this:-

var gps = (from g in db.GPSDATAs
           where (g.iVehicleID == id) &&
           (g.dtTime.Day == transDate.Day &&
           g.dtTime.Month == transDate.Month &&
           g.dtTime.Year == transDate.Year) &&
           (g.dtTime.Hour >= startTime.Hour &&
           g.dtTime.Hour <= endTime.Hour) &&
           (g.dtTime.Minute >= startTime.Minute &&
           g.dtTime.Minute <= endTime.Minute)

it returns less data than sql query.

1 solution


You can write your sql sintax as a linq query like this:

var itemsList = from itm in db.MyTable where itm.myDate >= startDate && itm.myDate <= stopDate

In your linq query you have a condition for vehicleId and in the sql query above there is no such condition.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900