-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
代码优化:sqlserver特有的recompile相关处理 放到SqlServer包中;
- Loading branch information
hanzhiyuan
committed
Jun 13, 2024
1 parent
74b6d94
commit 9b0d9a2
Showing
13 changed files
with
190 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using NuClear.Dapper.AggregateQueryObject; | ||
using NuClear.Dapper.QueryObject; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuClear.Dapper.SqlServer | ||
{ | ||
public static class IRepositoryExtensions | ||
{ | ||
private static SqlServerRepositoryBase<TKey, TEntity> CheckAndConvertToSqlServerRepositoryBase<TKey, TEntity>(IRepository<TKey, TEntity> repository) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
if (!(repository is SqlServerRepositoryBase<TKey, TEntity> sqlServerRepository)) | ||
{ | ||
throw new NotSupportedException("不支持recompile参数!"); | ||
} | ||
|
||
return sqlServerRepository; | ||
} | ||
|
||
public static int CountWithRecompile<TKey, TEntity>(this IRepository<TKey, TEntity> repository, string sql, object parameters = null) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
var sqlServerRepository = CheckAndConvertToSqlServerRepositoryBase(repository); | ||
return sqlServerRepository.CountWithRecompile(sql, parameters); | ||
} | ||
|
||
|
||
|
||
public static async Task<int> CountWithRecompileAsync<TKey, TEntity>(this IRepository<TKey, TEntity> repository, string sql, object parameters = null) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
var sqlServerRepository = CheckAndConvertToSqlServerRepositoryBase(repository); | ||
return await sqlServerRepository.CountWithRecompileAsync(sql, parameters); | ||
} | ||
|
||
|
||
public static IEnumerable<TAny> QueryWithRecompile<TKey, TEntity, TAny>(this IRepository<TKey, TEntity> repository, string selectSql, Query query, Sort sort = null) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
var sqlServerRepository = CheckAndConvertToSqlServerRepositoryBase(repository); | ||
return sqlServerRepository.QueryWithRecompile<TKey, TEntity, TAny>(selectSql, query, sort); | ||
} | ||
public static IEnumerable<TAny> QueryWithRecompilePaged<TKey, TEntity, TAny>(this IRepository<TKey, TEntity> repository, string selectSql, Query query, Pager pager, Sort sort, AggrQuery aggrQuery = null) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
var sqlServerRepository = CheckAndConvertToSqlServerRepositoryBase(repository); | ||
return sqlServerRepository.QueryWithRecompilePaged<TKey, TEntity, TAny>(selectSql, query, pager, sort, aggrQuery); | ||
} | ||
|
||
public static IEnumerable<TAny> QueryWithRecompile<TKey, TEntity, TAny>(this IRepository<TKey, TEntity> repository, string query, object parameters = null) | ||
where TEntity : IEntity<TKey> | ||
{ | ||
var sqlServerRepository = CheckAndConvertToSqlServerRepositoryBase(repository); | ||
return sqlServerRepository.QueryWithRecompile<TKey, TEntity, TAny>(query, parameters); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.