C# 实体框架6二级缓存,将代码转换为vb.net
当我使用entity framework执行从数据到sql的大型导入时,我的代码必须检查相同的外键,这会导致向sql server重复命令。我相信我需要使用二级缓存,我尝试过使用,但由于我只习惯于vb.net,我在转换以下c代码时遇到了问题:C# 实体框架6二级缓存,将代码转换为vb.net,c#,vb.net,entity-framework,caching,C#,Vb.net,Entity Framework,Caching,当我使用entity framework执行从数据到sql的大型导入时,我的代码必须检查相同的外键,这会导致向sql server重复命令。我相信我需要使用二级缓存,我尝试过使用,但由于我只习惯于vb.net,我在转换以下c代码时遇到了问题: 我知道我需要将c++更改为addhandler,但它无法识别dbproviderservices、下划线和DefaultCachingPolicy。您使用的方法签名不正确 作为EventHandler加载的公共共享事件(属于DBConfiguratio
我知道我需要将c++更改为addhandler,但它无法识别dbproviderservices、下划线和DefaultCachingPolicy。您使用的方法签名不正确
-
作为EventHandler加载的公共共享事件(属于DBConfigurationLoadedEventTargets)
-
Public Sub-ReplaceService(属于TService)(serviceInterceptor作为Func(属于TService、Object、TService))
AddHandler已加载,
Sub(发送方作为对象,e作为DbConfigurationLoadedEventArgs)
e、 替换服务(DbProviderServices的)(
函数(serviceInterceptor作为DbProviderServices,o作为对象)
返回新的CachingProviderServices(serviceInterceptor、transactionHandler、New DefaultCachingPolicy())
终端功能)
端接头
紧凑型:
AddHandler-Loaded,Sub(发送方作为对象,e作为DbConfigurationLoadedEventArgs)e.ReplaceService(DbProviderServices的)(函数(serviceInterceptor作为DbProviderServices,o作为对象)New-CachingProviderServices(serviceInterceptor,transactionHandler,New-DefaultCachingPolicy())
选项是否关闭?我认为正确的方法签名是Sub(发送方作为对象,e作为dbconfigurationloadeventargs)
Reference:下划线本身不是有效的VB标识符-您必须重命名它。
public class Configuration : DbConfiguration
{
public Configuration()
{
var transactionHandler = new CacheTransactionHandler(new InMemoryCache());
AddInterceptor(transactionHandler);
Loaded +=
(sender, args) => args.ReplaceService<DbProviderServices>(
(s, _) => new CachingProviderServices(s, transactionHandler,
new DefaultCachingPolicy()));
}
}
Imports System.Data.Entity
Imports EFCache
Public Class Configuration
Inherits DbConfiguration
Public Sub New()
Dim transactionHandler = New CacheTransactionHandler(New InMemoryCache())
AddInterceptor(transactionHandler)
AddHandler Loaded, Function(sender, args) args.ReplaceService(Of
DbProviderServices)(Function(s, _) New CachingProviderServices(s,
transactionHandler, New DefaultCachingPolicy()))
End Sub
End Class