Skip to content

Commit 03198ef

Browse files
committed
Don't close the active reader
1 parent d3bd950 commit 03198ef

File tree

7 files changed

+301
-276
lines changed

7 files changed

+301
-276
lines changed

src/EFCoreSecondLevelCacheInterceptor/DbCommandInterceptorProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public T ProcessExecutedCommands<T>(DbCommand command, DbContext? context, T res
136136

137137
using (var dbReaderLoader = new EFDataReaderLoader(dataReader))
138138
{
139-
tableRows = dbReaderLoader.LoadAndClose();
139+
tableRows = dbReaderLoader.Load();
140140
}
141141

142142
if (!ShouldSkipCachingResults(commandText, tableRows))

src/EFCoreSecondLevelCacheInterceptor/EFCoreSecondLevelCacheInterceptor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>Entity Framework Core Second Level Caching Library.</Description>
4-
<VersionPrefix>4.8.4</VersionPrefix>
4+
<VersionPrefix>4.8.5</VersionPrefix>
55
<Authors>Vahid Nasiri</Authors>
66
<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netstandard2.1;netstandard2.0;net462;netcoreapp3.1;</TargetFrameworks>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/EFCoreSecondLevelCacheInterceptor/EFDataReaderLoader.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ public class EFDataReaderLoader : DbDataReader
2222
public EFDataReaderLoader(DbDataReader dbReader)
2323
{
2424
_dbReader = dbReader;
25+
2526
_tableRows = new EFTableRows(_dbReader)
26-
{
27-
FieldCount = _dbReader.FieldCount,
28-
VisibleFieldCount = _dbReader.VisibleFieldCount,
29-
};
27+
{
28+
FieldCount = _dbReader.FieldCount,
29+
VisibleFieldCount = _dbReader.VisibleFieldCount
30+
};
3031
}
3132

3233
/// <summary>
@@ -182,6 +183,7 @@ public EFDataReaderLoader(DbDataReader dbReader)
182183
public override int GetValues(object[] values)
183184
{
184185
Array.Copy(_rowValues, values, _rowValues.Length);
186+
185187
return _rowValues.Length;
186188
}
187189

@@ -231,15 +233,17 @@ public override bool Read()
231233
}
232234

233235
_tableRows?.Add(new EFTableRow(_rowValues)
234-
{
235-
Depth = _dbReader.Depth,
236-
});
236+
{
237+
Depth = _dbReader.Depth
238+
});
239+
237240
return true;
238241
}
239242

240243
private byte[] getSqlBytes(int ordinal)
241244
{
242245
byte[] buffer;
246+
243247
using (var stream = _dbReader.GetStream(ordinal))
244248
{
245249
if (stream.Length > int.MaxValue)
@@ -248,12 +252,14 @@ private byte[] getSqlBytes(int ordinal)
248252
}
249253

250254
buffer = new byte[stream.Length];
255+
251256
if (stream.Position != 0)
252257
{
253-
stream.Seek(0, SeekOrigin.Begin);
258+
stream.Seek(offset: 0, SeekOrigin.Begin);
254259
}
255260

256-
var count = stream.Read(buffer, 0, checked((int)stream.Length));
261+
var count = stream.Read(buffer, offset: 0, checked((int)stream.Length));
262+
257263
if (count <= 0)
258264
{
259265
return buffer;
@@ -266,21 +272,21 @@ private byte[] getSqlBytes(int ordinal)
266272
private bool isBinary(int ordinal)
267273
{
268274
var typeName = _tableRows.GetFieldTypeName(ordinal);
269-
return string.Equals(typeName, "Microsoft.SqlServer.Types.SqlGeography", StringComparison.Ordinal)
270-
|| string.Equals(typeName, "Microsoft.SqlServer.Types.SqlGeometry", StringComparison.Ordinal);
275+
276+
return string.Equals(typeName, b: "Microsoft.SqlServer.Types.SqlGeography", StringComparison.Ordinal) ||
277+
string.Equals(typeName, b: "Microsoft.SqlServer.Types.SqlGeometry", StringComparison.Ordinal);
271278
}
272279

273280
/// <summary>
274281
/// Converts a DbDataReader to an EFTableRows
275282
/// </summary>
276-
public EFTableRows LoadAndClose()
283+
public EFTableRows Load()
277284
{
278285
while (Read())
279286
{
280287
// Read all data
281288
}
282289

283-
Close();
284290
return _tableRows;
285291
}
286292
}

0 commit comments

Comments
 (0)