gpt4 book ai didi

c# - 如何在 Entity Framework 6 中禁用模型缓存(代码优先方法)

转载 作者:可可西里 更新时间:2023-11-01 08:08:45 25 4
gpt4 key购买 nike

正在关注 MSDN documentation我们可以阅读:

The model for that context is then cached and is for all further instances of the context in the app domain. This caching can be disabled by setting the ModelCaching property on the given ModelBuidler, but note that this can seriously degrade performance.

问题是模型构建器不包含任何名为 ModelCaching 的属性。

如何禁用模型缓存(例如,在运行时更改模型配置)?

最佳答案

我有同样的问题:一个数据库上下文,2 个或更多不同的数据库模型(仅表名不同)

我的 EF6 解决方案:仍然可以使用数据库模型的内部 Entity Framework 缓存,但通过在派生的 DbContext 上实现 IDbModelCacheKeyProvider 接口(interface) 来区分同一 DbContext 上的 DbModel。 p>

MSDN 文档在这里:https://msdn.microsoft.com/en-us/library/system.data.entity.infrastructure.idbmodelcachekeyprovider(v=vs.113).aspx它说:

Implement this interface on your context to use custom logic to calculate the key used to lookup an already created model in the cache. This interface allows you to have a single context type that can be used with different models in the same AppDomain, or multiple context types that use the same model.

希望对大家有帮助。

关于c# - 如何在 Entity Framework 6 中禁用模型缓存(代码优先方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29708128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com