小编dar*_*win的帖子

当用户为admin时包含IsDeleted值

isDeleted当用户是管理员时,我想将数据库中的值包括到索引中。我使用了全局查询过滤器来过滤数据。

这是我的代码:

var param = Expression.Parameter(entity.ClrType);

var propertyMethodInfo = typeof(EF).GetMethod("Property").MakeGenericMethod(typeof(bool));
var isDeleted = Expression.Call(propertyMethodInfo, param, Expression.Constant("IsDeleted"));

BinaryExpression compareExpression = Expression.MakeBinary(ExpressionType.Equal, isDeleted, Expression.Constant(false));

var lambdaExpression = Expression.Lambda(compareExpression, param);

builder.Entity(entity.ClrType).HasQueryFilter(lambdaExpression);
Run Code Online (Sandbox Code Playgroud)

c# lambda entity-framework-core

3
推荐指数
1
解决办法
326
查看次数

标签 统计

c# ×1

entity-framework-core ×1

lambda ×1