mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-08 02:14:53 +08:00
-
This commit is contained in:
@@ -1006,17 +1006,23 @@ namespace SqlSugar
|
||||
{
|
||||
List<TResult> result = null;
|
||||
var sqlObj = this.ToSql();
|
||||
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
|
||||
var entityType = typeof(TResult);
|
||||
result = GetData<TResult>(sqlObj, isComplexModel, entityType);
|
||||
RestoreMapping();
|
||||
SetContextModel(result, entityType);
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCache;
|
||||
result = CacheSchemeMain.GetOrCreate<List<TResult>>(cacheService, this.Context, this.QueryBuilder,()=> { return GetData<TResult>(sqlObj); });
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GetData<TResult>(sqlObj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj, bool isComplexModel, Type entityType)
|
||||
protected List<TResult> GetData<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||
{
|
||||
List<TResult> result;
|
||||
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
|
||||
var entityType = typeof(TResult);
|
||||
var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
if (typeof(TResult) == typeof(ExpandoObject))
|
||||
{
|
||||
@@ -1030,6 +1036,8 @@ namespace SqlSugar
|
||||
{
|
||||
result = this.Bind.DataReaderToList<TResult>(entityType, dataReader, QueryBuilder.SelectCacheKey);
|
||||
}
|
||||
RestoreMapping();
|
||||
SetContextModel(result, entityType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
20
Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs
Normal file
20
Src/Asp.Net/SqlSugar/CacheScheme/CacheEngines.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class CacheEngines
|
||||
{
|
||||
public string GetCacheMapping()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetCacheData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs
Normal file
15
Src/Asp.Net/SqlSugar/CacheScheme/CacheKeyBuider.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class CacheKeyBuider
|
||||
{
|
||||
public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs
Normal file
18
Src/Asp.Net/SqlSugar/CacheScheme/CacheSchemeMain.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class CacheSchemeMain
|
||||
{
|
||||
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, SqlSugarClient context, QueryBuilder queryBuilder,Func<T> getData)
|
||||
{
|
||||
string key = CacheKeyBuider.GetKey(context,queryBuilder).ToString();
|
||||
var result= cacheService.GetOrCreate(key, () => getData());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Src/Asp.Net/SqlSugar/Entities/CacheKey.cs
Normal file
14
Src/Asp.Net/SqlSugar/Entities/CacheKey.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class CacheKey
|
||||
{
|
||||
public new string ToString() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,10 @@
|
||||
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||
<Compile Include="Abstract\DeleteProvider\DeleteableProvider.cs" />
|
||||
<Compile Include="CacheScheme\CacheEngines.cs" />
|
||||
<Compile Include="CacheScheme\CacheKeyBuider.cs" />
|
||||
<Compile Include="CacheScheme\CacheSchemeMain.cs" />
|
||||
<Compile Include="Entities\CacheKey.cs" />
|
||||
<Compile Include="Enum\DbType.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\ISubOperation.cs" />
|
||||
<Compile Include="ExpressionsToSql\Subquery\Items\SubAnd.cs" />
|
||||
@@ -252,6 +256,7 @@
|
||||
<Content Include="References\Oracle.ManagedDataAccess.dll" />
|
||||
<Content Include="References\System.Data.SQLite.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Reference in New Issue
Block a user