【问题标题】:Entity Framework Core: Global select filterEntity Framework Core:全局选择过滤器
【发布时间】:2020-06-14 04:36:48
【问题描述】:

在 EF Core 中,您可以添加 global query filters 以排除满足某些条件的数据。我想知道全局选择实体的属性是否存在“相同”,例如全局排除来自ApplicationUser 的敏感信息来自.NET Core Identity

例如像这样:

builder.Entity<ApplicationUser>().HasSelectFilter(u => new ApplicationUser {
    Id = u.Id,
    Email = u.Email,
    ...
});

编辑:我刚刚发现你可以使用 builder.Entity&lt;ApplicationUser&gt;().Ignore(u =&gt; u.PasswordHash); 使用 FluentAPI 配置关系时。但是,它似乎在 Identity 中产生了问题。

Ignore properties in data model while keeping them in EF Core migrations

【问题讨论】:

    标签: .net-core entity-framework-core


    【解决方案1】:

    不,默认情况下,EF Core 不支持它。

    免责声明:我是项目的所有者Entity Framework Plus

    EF+ Query IncludeFilter(免费和开源)也允许将过滤器用作全局选择过滤器。

    例子:

    QueryFilterManager.Filter<Customer>(c => c.Select(x => new Customer() { CustomerId = x.CustomerId, Name = x.Name }));
    
    // ...code...
    
    var customers = context.Customers.ToList(); 
    

    在线示例:https://dotnetfiddle.net/wArKog

    【讨论】:

      猜你喜欢
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      相关资源
      最近更新 更多