Skip to content

Commit 1ff9027

Browse files
Update source
1 parent a80672f commit 1ff9027

File tree

2 files changed

+55
-27
lines changed

2 files changed

+55
-27
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ public static string GetCacheKey(IQueryable query, string[] tags, bool isAsync =
583583
sb.Append(";");
584584
sb.Append(parameter.Value);
585585
sb.AppendLine(";");
586+
586587

587588
// Array contient IList
588589
if (parameter.Value is IList parameterValues)
@@ -601,6 +602,33 @@ public static string GetCacheKey(IQueryable query, string[] tags, bool isAsync =
601602
}
602603
}
603604
}
605+
else if (parameter.Value is IEnumerable<object> enumerable)
606+
{
607+
// je prend pour acquit que si cela résout une query EF.Core ne sera résolut qu'une seul fois et qu'après le tracking embarquera...
608+
var paramValueNotIList = enumerable.ToList();
609+
610+
foreach (var param in paramValueNotIList)
611+
{
612+
if (param is DbParameter dbParameter)
613+
{
614+
sb.Append(dbParameter.Value?.ToString() ?? "NULL");
615+
sb.AppendLine(";");
616+
}
617+
else if (param != null)
618+
{
619+
try
620+
{
621+
sb.Append(param);
622+
sb.AppendLine(";");
623+
}
624+
catch (Exception ex)
625+
{
626+
// autant string, int et autre je me dit que ça va autant si sa tente de mettre une classe json ou autre sa risque de faire bomb.
627+
throw new Exception("Oops! The JSON? parameter list could not have been appended to create the key");
628+
}
629+
}
630+
}
631+
}
604632
}
605633
#endif
606634

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void ExecuteQueries()
119119
}
120120
#endif
121121

122-
if (!allowQueryBatch)
122+
if (!allowQueryBatch)
123123
{
124124
foreach (var query in Queries)
125125
{
@@ -239,12 +239,12 @@ public void ExecuteQueries()
239239
#if EFCORE
240240
}
241241
finally
242-
{
243-
if (firstQuery.RestoreConnection != null)
244-
{
245-
firstQuery.RestoreConnection();
246-
}
247-
}
242+
{
243+
if (firstQuery.RestoreConnection != null)
244+
{
245+
firstQuery.RestoreConnection();
246+
}
247+
}
248248
#endif
249249
}
250250

@@ -297,7 +297,7 @@ public void ExecuteQueries()
297297
#endif
298298
#if EFCORE
299299
try
300-
{
300+
{
301301
#endif
302302
var command = CreateCommandCombined(true);
303303

@@ -359,15 +359,15 @@ public void ExecuteQueries()
359359

360360
#if EFCORE
361361
}
362-
finally
363-
{
362+
finally
363+
{
364364
if (firstQuery.RestoreConnection != null)
365365
{
366366
firstQuery.RestoreConnection();
367367
}
368-
}
368+
}
369369
#endif
370-
}
370+
}
371371
#endif
372372

373373
/// <summary>Creates a new command combining deferred queries.</summary>
@@ -383,11 +383,11 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
383383
var isOracleManaged = command.GetType().FullName.Contains("Oracle.ManagedDataAccess");
384384
var isOracleDevArt = command.GetType().FullName.Contains("Devart");
385385

386-
var isPostgreSQL = command.GetType().FullName.Contains("Npgsql");
386+
var isPostgreSQL = command.GetType().FullName.Contains("Npgsql");
387387
#if EFCORE_3X
388388
// foreach is broken need stop and new Foreach, a for is better here, but I don't know if is possible Include with logique with new IncludeOptimized in a Where logic or other. In theory I guess yes, in true I don't know.
389389
// For now I try without check that.
390-
for (int i = 0; i < Queries.Count;i++)
390+
for (int i = 0; i < Queries.Count; i++)
391391
{
392392
var query = Queries.ElementAt(i);
393393
// first check is because parano.
@@ -411,7 +411,7 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
411411

412412
foreach (var query in Queries)
413413
{
414-
// GENERATE SQL
414+
// GENERATE SQL
415415
#if EF5
416416
var sql = query.Query.ToTraceString();
417417
var parameters = query.Query.Parameters;
@@ -481,7 +481,7 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
481481
int i = 0;
482482
object value;
483483
MethodInfo methodeConvertFromProvider;
484-
object convertToProvider;
484+
object convertToProvider;
485485

486486
// UPDATE parameter name
487487
foreach (var relationalParameter in parameters)
@@ -542,16 +542,16 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
542542
oldValue = parameterToCheck.Name.Substring(1);
543543
}
544544
else
545-
{
545+
{
546546
oldValue = relationalParameter.InvariantName;
547547
}
548548
var newValue = string.Concat("Z_", queryCount, "_", oldValue);
549549

550550
// CREATE parameter
551551
var dbParameter = command.CreateParameter();
552-
dbParameter.CopyFrom(relationalParameter, value ?? parameter, newValue, Context);
552+
dbParameter.CopyFrom(relationalParameter, value ?? parameter, newValue, Context);
553553

554-
if (methodeConvertFromProvider != null)
554+
if (methodeConvertFromProvider != null)
555555
{
556556
dbParameter.Value = methodeConvertFromProvider.Invoke(convertToProvider, new[] { dbParameter.Value });
557557
}
@@ -570,7 +570,7 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
570570
var relationalTypeMapping = (RelationalTypeMapping)relationalTypeMappingProperty.GetValue(relationalParameter);
571571

572572
if (relationalTypeMapping != null && relationalTypeMapping.StoreType.Equals("citext", StringComparison.OrdinalIgnoreCase))
573-
{
573+
{
574574

575575
var propertyPostgreSQLDBType = dbParameter.GetType().GetProperty("NpgsqlDbType", BindingFlags.Public | BindingFlags.Instance);
576576

@@ -603,7 +603,7 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
603603

604604

605605

606-
sb.AppendLine(string.Concat("-- EF+ Query Future: ", queryCount, " of ", Queries.Count));
606+
sb.AppendLine(string.Concat("-- EF+ Query Future: ", queryCount, " of ", Queries.Count));
607607

608608
if (isOracle || isOracleManaged || isOracleDevArt)
609609
{
@@ -615,16 +615,16 @@ protected DbCommand CreateCommandCombined(bool isAsync = false)
615615
param.Value = DBNull.Value;
616616

617617
if (isOracle)
618-
{
619-
SetOracleDbType(command.GetType().Assembly, param, 121);
618+
{
619+
SetOracleDbType(command.GetType().Assembly, param, 121);
620620
}
621621
else if (isOracleManaged)
622-
{
623-
SetOracleManagedDbType(command.GetType().Assembly, param, 121);
622+
{
623+
SetOracleManagedDbType(command.GetType().Assembly, param, 121);
624624
}
625625
else if (isOracleDevArt)
626-
{
627-
SetOracleDevArtDbType(command.GetType().Assembly, param, 7);
626+
{
627+
SetOracleDevArtDbType(command.GetType().Assembly, param, 7);
628628
}
629629

630630

0 commit comments

Comments
 (0)