EF动态过滤器表达式
我们正在使用EF动态过滤器(ASP.NET MVC 5应用程序) https://entityframeframeworkerwork-dynamicfilters.net/overview
下面的过滤器只能设置一次。
builder.Filter("IMultiOrganization", (IMultOrganization d) => ((d.TenantId == GlobalAppVariables.IssuerId) && (d.IsShared == true)) || ((d.IsShared == false && d.AzureObjIdentifier == GlobalAppVariables.AzureObjIdentifier)));
变量“ issuerId”和“ azureobjistientifier”是动态的会话变量,这些变量一直在改变。这会导致问题,我希望过滤器可以直接使用这些变量。
根据文档,这是因为该文件不是代表表达式引起的。
可以通过提供特定值来定义特定实体类或接口上的过滤器,例如在IsoftDelete接口上创建的ISDEATED过滤器,该过滤器将通过应用“ ISDETERTED == false”的条件来自动过滤这些实体。
滤波器值也可以通过委托/表达式而不是特定值提供,该值允许您动态更改参数值。例如,可以在用户ID上创建过滤器并根据HTTP请求提供。
我们还使用委托过滤器确实有效。
builder.EnableFilter("IMultiTenant", () => GlobalAppVariables.AzureObjIdentifier != null || GlobalAppVariables.IssuerId != Guid.Empty);
但是我无法将第一个过滤器作为代表表达式工作,并且需要一些帮助。
We are using EF Dynamic filters (ASP.NET MVC 5 app)
https://entityframework-dynamicfilters.net/overview
The filter below is working, but set only once.
builder.Filter("IMultiOrganization", (IMultOrganization d) => ((d.TenantId == GlobalAppVariables.IssuerId) && (d.IsShared == true)) || ((d.IsShared == false && d.AzureObjIdentifier == GlobalAppVariables.AzureObjIdentifier)));
The variables 'IssuerId' and 'AzureObjIdentifier' are dynamic session variables, those are changing all the time. This causes problems and I would like the filter to use those variables straight from the session.
According to the documentation this is caused because this filer isn't a delegate expression.
Filters can be defined on a specific entity class or an interface by providing a specific value, e.g. an IsDeleted filter created on an ISoftDelete interface which will automatically filter those entities by applying the condition "IsDeleted==false".
Filter values can also be provided via a delegate/expression instead of a specific value which allows you to change the parameter value dynamically. For example, a filter can be created on the UserID and provided per HTTP request.
We also use delegate filters what indeed is working fine.
builder.EnableFilter("IMultiTenant", () => GlobalAppVariables.AzureObjIdentifier != null || GlobalAppVariables.IssuerId != Guid.Empty);
But I can't get the first filter work as a delegate expression and need a bit help on that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过在过滤器中使用参数找到解决方案。
首先,我更改了现在支持参数的过滤器。
然后,我在DB上下文中调用下面的方法构造函数
来源: https://github.com/zzzprojects/entityframework.dynamicfilters#changing-filter-parameter-values
I found the solution by using parameters within the filter.
First of all I changed the filter which now supports parameters.
Then I call method below in the db context constructor
Source: https://github.com/zzzprojects/EntityFramework.DynamicFilters#changing-filter-parameter-values