简体   繁体   English

ef核心中的hasqueryfilter错误

[英]hasqueryfilter error in ef core

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'. InvalidCastException:无法将类型为“ System.DateTime”的对象转换为类型为“ System.Linq.Expressions.LambdaExpression”。

The created_at property is typed to DateTime. created_at属性的类型为DateTime。

What am I missing? 我想念什么?

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. 不知道为什么Datetime.Today会引发错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM