0
modelBuilder.Entity<SomeEntity>().HasQueryFilter(e => e.created_at.Date == DateTime.Today);

produces this error:

InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.Linq.Expressions.LambdaExpression'.

The created_at property is typed to DateTime.

What am I missing?

3
  • I'm not to sure what Created_at is but it its a regular date Mostly likely your missing beta version of .NET-Core. if you upgrade to 2.1 this should be fixed.
    – johnny 5
    May 1, 2018 at 1:04
  • I am running 2.1.0-preview1-26216-03
    – bebo925
    May 1, 2018 at 1:32
  • sorry my fault I think I know the answer
    – johnny 5
    May 1, 2018 at 1:34

1 Answer 1

0

This seems to get it:

 modelBuilder.Entity<SomeEntity>()
      .HasQueryFilter(b => EF.Property<DateTime>(b, "created_at").Date == DateTime.Now.Date);

Not sure why Datetime.Today throws the error though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.