Skip to content

Commit 47c2aab

Browse files
author
zzzprojects
committed
Add fix 1.7.10
Add fix 1.7.10
1 parent cfa9657 commit 47c2aab

File tree

10 files changed

+109
-59
lines changed

10 files changed

+109
-59
lines changed

src/shared/Z.EF.Plus.BatchUpdate.Shared/BatchUpdate.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
585585
parameter.Value = paramValue ?? DBNull.Value;
586586
}
587587
}
588-
589588

590589
if (parameter is SqlParameter)
591590
{

src/shared/Z.EF.Plus.QueryCache.Shared/Extensions/IQueryable`/FromCache.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static IEnumerable<T> FromCache<T>(this IQueryable<T> query, CacheItemPol
4949
QueryCacheManager.AddCacheTag(key, tags);
5050
}
5151

52+
item = item.IfDbNullThenNull();
53+
5254
return (IEnumerable<T>) item;
5355
}
5456

@@ -77,6 +79,8 @@ public static IEnumerable<T> FromCache<T>(this IQueryable<T> query, DateTimeOffs
7779
QueryCacheManager.AddCacheTag(key, tags);
7880
}
7981

82+
item = item.IfDbNullThenNull();
83+
8084
return (IEnumerable<T>) item;
8185
}
8286

@@ -120,6 +124,8 @@ public static IEnumerable<T> FromCache<T>(this IQueryable<T> query, MemoryCacheE
120124
QueryCacheManager.AddCacheTag(key, tags);
121125
}
122126

127+
item = item.IfDbNullThenNull();
128+
123129
return (IEnumerable<T>)item;
124130
}
125131

src/shared/Z.EF.Plus.QueryCache.Shared/Extensions/IQueryable`/FromCacheAsync.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, C
5353
QueryCacheManager.AddCacheTag(key, tags);
5454
}
5555

56+
item = item.IfDbNullThenNull();
57+
5658
return (IEnumerable<T>) item;
5759
});
5860

@@ -86,6 +88,8 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, D
8688
QueryCacheManager.AddCacheTag(key, tags);
8789
}
8890

91+
item = item.IfDbNullThenNull();
92+
8993
return (IEnumerable<T>) item;
9094
});
9195

@@ -134,6 +138,8 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, p
134138
QueryCacheManager.AddCacheTag(key, tags);
135139
}
136140

141+
item = item.IfDbNullThenNull();
142+
137143
return (IEnumerable<T>) item;
138144
}
139145

@@ -180,6 +186,8 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, C
180186
QueryCacheManager.AddCacheTag(key, tags);
181187
}
182188

189+
item = item.IfDbNullThenNull();
190+
183191
return (IEnumerable<T>) item;
184192
}
185193

@@ -258,6 +266,8 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, p
258266
QueryCacheManager.AddCacheTag(key, tags);
259267
}
260268

269+
item = item.IfDbNullThenNull();
270+
261271
return (IEnumerable<T>) item;
262272
}
263273

src/shared/Z.EF.Plus.QueryCache.Shared/Extensions/QueryDeferred`/FromCache.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ public static T FromCache<T>(this QueryDeferred<T> query, CacheItemPolicy policy
4545
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
4646
QueryCacheManager.AddCacheTag(key, tags);
4747
}
48-
else
49-
{
50-
if (item == DBNull.Value)
51-
{
52-
item = null;
53-
}
54-
}
48+
49+
item = item.IfDbNullThenNull();
5550

5651
return (T) item;
5752
}
@@ -81,13 +76,8 @@ public static T FromCache<T>(this QueryDeferred<T> query, DateTimeOffset absolut
8176
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
8277
QueryCacheManager.AddCacheTag(key, tags);
8378
}
84-
else
85-
{
86-
if (item == DBNull.Value)
87-
{
88-
item = null;
89-
}
90-
}
79+
80+
item = item.IfDbNullThenNull();
9181

9282
return (T) item;
9383
}
@@ -132,13 +122,8 @@ public static T FromCache<T>(this QueryDeferred<T> query, MemoryCacheEntryOption
132122
item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
133123
QueryCacheManager.AddCacheTag(key, tags);
134124
}
135-
else
136-
{
137-
if (item == DBNull.Value)
138-
{
139-
item = null;
140-
}
141-
}
125+
126+
item = item.IfDbNullThenNull();
142127

143128
return (T)item;
144129
}

src/shared/Z.EF.Plus.QueryCache.Shared/Extensions/QueryDeferred`/FromCacheAsync.cs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,8 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, CacheItemPo
4848
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
4949
QueryCacheManager.AddCacheTag(key, tags);
5050
}
51-
else
52-
{
53-
if (item == DBNull.Value)
54-
{
55-
item = null;
56-
}
57-
}
51+
52+
item = item.IfDbNullThenNull();
5853

5954
return (T) item;
6055
});
@@ -88,13 +83,8 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, DateTimeOff
8883
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
8984
QueryCacheManager.AddCacheTag(key, tags);
9085
}
91-
else
92-
{
93-
if (item == DBNull.Value)
94-
{
95-
item = null;
96-
}
97-
}
86+
87+
item = item.IfDbNullThenNull();
9888

9989
return (T) item;
10090
});
@@ -143,13 +133,8 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, params stri
143133
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, policy) ?? item;
144134
QueryCacheManager.AddCacheTag(key, tags);
145135
}
146-
else
147-
{
148-
if (item == DBNull.Value)
149-
{
150-
item = null;
151-
}
152-
}
136+
137+
item = item.IfDbNullThenNull();
153138

154139
return (T) item;
155140
}
@@ -196,13 +181,8 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, CacheItemPo
196181
item = QueryCacheManager.Cache.AddOrGetExisting(key, item ?? DBNull.Value, absoluteExpiration) ?? item;
197182
QueryCacheManager.AddCacheTag(key, tags);
198183
}
199-
else
200-
{
201-
if (item == DBNull.Value)
202-
{
203-
item = null;
204-
}
205-
}
184+
185+
item = item.IfDbNullThenNull();
206186

207187
return (T) item;
208188
}
@@ -281,13 +261,8 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, params stri
281261
item = QueryCacheManager.Cache.Set(key, item ?? DBNull.Value, options);
282262
QueryCacheManager.AddCacheTag(key, tags);
283263
}
284-
else
285-
{
286-
if (item == DBNull.Value)
287-
{
288-
item = null;
289-
}
290-
}
264+
265+
item = item.IfDbNullThenNull();
291266

292267
return (T) item;
293268
}

src/shared/Z.EF.Plus.QueryFilterInterceptor.Shared/QueryFilterInterceptorManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static void ClearQueryCache(DbContext context)
221221
{
222222
var objectQuery = dbSet.GetObjectQuery();
223223

224-
var stateField = objectQuery.GetType().BaseType.GetField("_state", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
224+
var stateField = objectQuery.GetType().BaseType.GetField("_state", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, true);
225225
var state = stateField.GetValue(objectQuery);
226226

227227
var cachedPlanField = state.GetType().GetField("_cachedPlan", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Description: Entity Framework Bulk Operations & Utilities (EF Bulk SaveChanges, Insert, Update, Delete, Merge | LINQ Query Cache, Deferred, Filter, IncludeFilter, IncludeOptimize | Audit)
2+
// Website & Documentation: https://github.com/zzzprojects/Entity-Framework-Plus
3+
// Forum & Issues: https://github.com/zzzprojects/EntityFramework-Plus/issues
4+
// License: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
8+
#if FULL || QUERY_CACHE
9+
10+
using System;
11+
12+
namespace Z.EntityFramework.Plus
13+
{
14+
internal static partial class InternalExtensions
15+
{
16+
/// <summary>An object extension method that return null if the value is DBNull.Value.</summary>
17+
/// <param name="item">The item to act on.</param>
18+
/// <returns>Null if the value is DBNull.Value.</returns>
19+
public static object IfDbNullThenNull(this object item)
20+
{
21+
if (item == DBNull.Value)
22+
{
23+
item = null;
24+
}
25+
26+
return item;
27+
}
28+
}
29+
}
30+
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using System.Text;
5+
6+
#if FULL || BATCH_DELETE || BATCH_UPDATE || QUERY_CACHE || QUERY_FILTER || QUERY_FUTURE || QUERY_INCLUDEOPTIMIZED
7+
#if EF5 || EF6
8+
9+
namespace Z.EntityFramework.Plus
10+
{
11+
internal static partial class InternalExtensions
12+
{
13+
/// <summary>A Type extension method that gets a field.</summary>
14+
/// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
15+
/// <param name="type">The type to act on.</param>
16+
/// <param name="name">The name.</param>
17+
/// <param name="bindingAttr">The binding attribute.</param>
18+
/// <param name="recursif">True to recursif.</param>
19+
/// <returns>The field.</returns>
20+
public static FieldInfo GetField(this Type type, string name, BindingFlags bindingAttr, bool recursif)
21+
{
22+
FieldInfo fieldinfo;
23+
if (!recursif)
24+
{
25+
fieldinfo = type.GetField(name, bindingAttr);
26+
}
27+
else
28+
{
29+
fieldinfo = type.GetField(name, bindingAttr);
30+
31+
if(fieldinfo == null && type != typeof(object))
32+
{
33+
fieldinfo = type.BaseType.GetField(name, bindingAttr, true);
34+
}
35+
}
36+
37+
return fieldinfo;
38+
}
39+
}
40+
}
41+
42+
#endif
43+
#endif

src/shared/Z.EF.Plus._Core.Shared/EF6/ObjectQuery/GetCommandTextAndParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static partial class InternalExtensions
2121
{
2222
public static Tuple<string, DbParameterCollection> GetCommandTextAndParameters(this ObjectQuery objectQuery)
2323
{
24-
var stateField = objectQuery.GetType().BaseType.GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance);
24+
var stateField = objectQuery.GetType().BaseType.GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance, true);
2525
var state = stateField.GetValue(objectQuery);
2626
var getExecutionPlanMethod = state.GetType().GetMethod("GetExecutionPlan", BindingFlags.NonPublic | BindingFlags.Instance);
2727
var getExecutionPlan = getExecutionPlanMethod.Invoke(state, new object[] {null});

src/shared/Z.EF.Plus._Core.Shared/Z.EF.Plus._Core.Shared.projitems

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
<Compile Include="$(MSBuildThisFileDirectory)EF\IQueryable`\IQueryable.OrderByDescending.cs" />
6868
<Compile Include="$(MSBuildThisFileDirectory)EF\IQueryable`\IQueryable.ThenBy.cs" />
6969
<Compile Include="$(MSBuildThisFileDirectory)EF\IQueryable`\IQueryable.ThenByDescending.cs" />
70+
<Compile Include="$(MSBuildThisFileDirectory)EF\Object\Object.NullIfDbNull.cs" />
7071
<Compile Include="$(MSBuildThisFileDirectory)EF\Type\Type.GetDbSetElementType.cs" />
72+
<Compile Include="$(MSBuildThisFileDirectory)EF\Type\Type.GetField.cs" />
7173
<Compile Include="$(MSBuildThisFileDirectory)Extensions\List`\List`.GetVersion.cs" />
7274
<Compile Include="$(MSBuildThisFileDirectory)LazyAsyncEnumerator\LazyAsyncEnumerator.cs" />
7375
<Compile Include="$(MSBuildThisFileDirectory)LinqExpressionExtensions\LambdaExpression\LambdaExpression.GetPropertyOrFieldAccessor.cs" />

0 commit comments

Comments
 (0)