我需要重用可用的表达式:
Expression<Func<Picture, int>> selector = o => o.EntityId;
并为Where构建表达式:
Expression<Func<Picture, bool>> filter = w => w.EntityId > 5;
如何构建这样的表达式?
下一步操作不会在客户端执行,对吗?
var collection = _dbContext.Pictures.Where(filter).ToList();
配置您的DbContext以禁止客户端评估和测试。
例如
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFQuerying;Trusted_Connection=True;")
.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
}
请参见https://docs.microsoft.com/en-us/ef/core/querying/client-eval#previous-versions