cmaduro
cmaduro

Reputation: 1722

DataServiceOperationException in Lightswitch query

Can anyone tell me what could possible be wrong with the date comparison here?

No property 'Date' exists in type 'Edm.DateTime' at position 60 "reffering to s.SwipeDateTime.Value.Date"

        var lastSwipe = (from s in this.DataWorkspace.ApplicationData.EmployeeSwipeLogs
                         where s.Employee.Id == emp.Id &&
                         s.SwipeIsValid == true &&
                         s.SwipeDateTime.Value.Date == DateTime.Today
                         orderby s.SwipeDateTime descending
                         select s).FirstOrDefault();

Upvotes: 1

Views: 298

Answers (3)

Yann Duran
Yann Duran

Reputation: 3879

You may also find Entity Functions useful. These allow you to use some methods that you otherwise wouldn't be able to use.

You'll need to add:

  • An assembly reference in your project to System.Data.Entity (in System.Data.Entity.dll)
  • An Imports/using System.Data.Objects statement in the class that you're using the functions

Upvotes: 1

cmaduro
cmaduro

Reputation: 1722

If you are using Entity framework then you are right the EDM.DateTime does not have a .Date property. Check out EDM.DateTime for what methods you can use.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500675

Quite simply, the LINQ provider you're using probably doesn't support Convert.ToDateTime. What's the type of s.SwipeDateTime anyway? If it's already DateTime, you shouldn't need to convert in the first place - and if it's not DateTime, it probably should be. Note that you can use DateTime.Today instead of DateTime.Now.Date, and personally I'd move that to before the query.

Upvotes: 1

Related Questions