Skip to content

Commit 9e3aca3

Browse files
Update source
Update source
1 parent 3ae867f commit 9e3aca3

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

src/shared/Z.EF.Plus.QueryCache.Shared/QueryCacheManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,18 @@ public static string GetCacheKey(IQueryable query, string[] tags)
534534
sb.Append(";");
535535
sb.Append(parameter.Value);
536536
sb.AppendLine(";");
537+
538+
if (parameter.Value is object[] parameterValues)
539+
{
540+
foreach (var param in parameterValues)
541+
{
542+
if (param is DbParameter dbParameter)
543+
{
544+
sb.Append(dbParameter.Value?.ToString() ?? "NULL");
545+
sb.AppendLine(";");
546+
}
547+
}
548+
}
537549
}
538550
#endif
539551

src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureValue.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
 // Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
1+
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
22
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
33
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
44
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
@@ -11,6 +11,7 @@
1111
using System.Data;
1212
using System.Data.Common;
1313
using System.Linq;
14+
using System.Linq.Expressions;
1415
using System.Threading;
1516
using System.Threading.Tasks;
1617
#if EF5
@@ -76,8 +77,8 @@ public TResult Value
7677
/// <value>The value of the future query.</value>
7778
public async Task<TResult> ValueAsync(CancellationToken cancellationToken = default(CancellationToken))
7879
{
79-
cancellationToken.ThrowIfCancellationRequested();
80-
if (!HasValue)
80+
cancellationToken.ThrowIfCancellationRequested();
81+
if (!HasValue)
8182
{
8283
#if EF6
8384
if (Query.Context.IsInMemoryEffortQueryContext())
@@ -91,32 +92,32 @@ public TResult Value
9192
#else
9293
await OwnerBatch.ExecuteQueriesAsync(cancellationToken).ConfigureAwait(false);
9394
#endif
94-
}
95+
}
9596

96-
return _result;
97+
return _result;
9798
}
9899
#endif
99100

100-
/// <summary>Sets the result of the query deferred.</summary>
101-
/// <param name="reader">The reader returned from the query execution.</param>
101+
/// <summary>Sets the result of the query deferred.</summary>
102+
/// <param name="reader">The reader returned from the query execution.</param>
102103
public override void SetResult(DbDataReader reader)
103104
{
104105
if (reader.GetType().FullName.Contains("Oracle"))
105106
{
106107
var reader2 = new QueryFutureOracleDbReader(reader);
107108
reader = reader2;
108109
}
109-
110+
110111
var enumerator = GetQueryEnumerator<TResult>(reader);
111112
using (enumerator)
112113
{
113114
enumerator.MoveNext();
114115
_result = enumerator.Current;
115116

116117
}
117-
118+
118119
// Enumerate on first item only
119-
120+
120121
HasValue = true;
121122
}
122123

@@ -136,16 +137,13 @@ public override void ExecuteInMemory()
136137
#if EFCORE
137138
var query = (IQueryable<TResult>)Query;
138139

139-
object value = null;
140-
141-
if (!typeof(TResult).IsPrimitive)
140+
var expression = query.Expression;
141+
if (expression.Type != typeof(object))
142142
{
143-
value = query.Provider.Execute<object>(query.Expression);
143+
expression = Expression.Convert(expression, typeof(object));
144144
}
145-
else
146-
{
147-
value = query.Provider.Execute<TResult>(query.Expression);
148-
}
145+
146+
var value = query.Provider.Execute<object>(expression);
149147

150148
if (value is TResult valueTResult)
151149
{
@@ -183,18 +181,18 @@ public override void ExecuteInMemory()
183181
#endif
184182
public override void GetResultDirectly()
185183
{
186-
var query = (IQueryable<TResult>) Query;
184+
var query = (IQueryable<TResult>)Query;
187185
#if EFCORE_3X
188186
object value = null;
189187

190188
if (!typeof(TResult).IsPrimitive)
191189
{
192-
value = query.Provider.Execute<object>(query.Expression);
190+
value = query.Provider.Execute<object>(query.Expression);
193191
}
194192
else
195193
{
196194
value = query.Provider.Execute<TResult>(query.Expression);
197-
}
195+
}
198196

199197
if (value is TResult valueTResult)
200198
{
@@ -234,7 +232,7 @@ public override async Task GetResultDirectlyAsync(CancellationToken cancellation
234232
public override Task GetResultDirectlyAsync(CancellationToken cancellationToken)
235233
#endif
236234
{
237-
cancellationToken.ThrowIfCancellationRequested();
235+
cancellationToken.ThrowIfCancellationRequested();
238236

239237
#if EF6
240238
var query = (IQueryable<TResult>)Query;
@@ -243,11 +241,11 @@ public override Task GetResultDirectlyAsync(CancellationToken cancellationToken)
243241
_result = value;
244242
HasValue = true;
245243
#else
246-
GetResultDirectly();
244+
GetResultDirectly();
247245
return Task.FromResult(0);
248246
#endif
249247

250-
}
248+
}
251249
#endif
252250

253251

0 commit comments

Comments
 (0)