仅为 select 查询忽略实体属性。但在 update/insert 期间仍会考虑它们。英孚核心 2.1

Ignore entity properties only for select queries. But still consider them during update/insert. EF Core 2.1

我有以下问题: 我在 Ef 上下文中有大约 80 个 DBSet。所有这些实体都继承自 HistoricalEntity class,其中包含历史字段,如 (AddDate、AddSource、ChangeDate、ChangeSource)。我想找到一个解决方案,如何在每个查询中不 select 这些字段。有没有办法一次性做到全局?比如设置全局查询过滤器?

此外,我尝试使用 NotMapped 属性和 Fluent API 方法忽略,但在这些情况下,历史属性的更新和插入操作被阻止。

换句话说,我不想 select 所有查询中的历史字段,但我仍然想更新并插入它们。

提前致谢

EF Core 有 Shadow Properties

Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker.