时间:2021-07-01 10:21:17 帮助过:36人阅读
启用IsBrokerEnabled
ALTER DATABASE [DATABASENAME] SET NEW_BROKER WITH ROLLBACK IMMEDIATE; ALTER DATABASE [DATABASENAME] SET ENABLE_BROKER;/ALTER DATABASE [DATABASENAME] SET DISABLE_BROKER;
设置权限信息
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [当前数据库登录用户名,如果是sa可以跳过]
修改登录账号信息,这里比较关键,如果未设置有可能通知是没有权限的。具体也可以看看SQL日志信息
exec sp_changedbowner @loginame = ‘[当前数据库登录用户名,如果是sa,则使用sa账号]‘
首先添加web.config的配置信息
<configSections> <section name="DMSLinqCacheProvider" type="DMSFrame.Cache.DMSLinqCacheProvider,DMSFrame"/> </configSections> <DMSLinqCacheProvider> <add key="provider" providerName="MsSql" value="DMSFrame.Cache.DMSLinqSqlWebCacheNotifyProvider,DMSFrame"/> </DMSLinqCacheProvider>
最最重要的TableConfig配置数据库加上标记CacheDependency,已便支持CacheDependency
<TableConfiguration> <Name>DefaultValue</Name> <SqlType>MsSql</SqlType> <WithLock>false</WithLock> <Author>dbo</Author> <CacheDependency>true</CacheDependency> <ConnectString>Integrated Security=False;server=127.0.0.1;database=database;User ID=sa;Password=sa;Connect Timeout=30</ConnectString> </TableConfiguration>
最后就是查询SQL了,
ToList(bool DependencyFlag) 增加了是否使用缓存的标记参数。
var resultAccess = DMS.Create<Adm_User>() .Where(q => q.UserID == 1) .Select(q => q.Columns(q.UserID, q.UpdateTime)).ToList(true);
通知模式的SQL运行跟踪如图:
DMSFrame 之SqlCacheDependency(一)
标签: