Skip to content

Commit 1743d82

Browse files
author
zzzprojects
committed
Update to v1.0.6 | v.1.0.7
Update to v1.0.6 | v.1.0.7
1 parent 81aad76 commit 1743d82

File tree

105 files changed

+8515
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+8515
-538
lines changed

src/Z.EntityFramework.Plus.EF5.NET40/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
[assembly: AssemblyCulture("")]
1919
[assembly: ComVisible(false)]
2020
[assembly: Guid("e4c2af73-caeb-4429-bcb6-0a359484e064")]
21-
[assembly: AssemblyVersion("1.0.5")]
22-
[assembly: AssemblyFileVersion("1.0.5")]
21+
[assembly: AssemblyVersion("1.0.6")]
22+
[assembly: AssemblyFileVersion("1.0.6")]

src/Z.EntityFramework.Plus.EF5.NET40/QueryCache/Extensions/IQueryable`/FromCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
using System.Data.Entity;
1313
using System.Runtime.Caching;
1414

15-
#elif EF7
15+
#elif EFCORE
1616
using Microsoft.Data.Entity;
1717
using Microsoft.Extensions.Caching.Memory;
1818

@@ -94,7 +94,7 @@ public static IEnumerable<T> FromCache<T>(this IQueryable<T> query, params strin
9494
{
9595
return query.FromCache(QueryCacheManager.DefaultCacheItemPolicy, tags);
9696
}
97-
#elif EF7
97+
#elif EFCORE
9898
/// <summary>
9999
/// Return the result of the <paramref name="query" /> from the cache. If the query is not cached
100100
/// yet, the query is materialized asynchronously and cached before being returned.

src/Z.EntityFramework.Plus.EF5.NET40/QueryCache/Extensions/IQueryable`/FromCacheAsync.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// More projects: http://www.zzzprojects.com/
66
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
77

8-
98
#if NET45
109
using System.Collections.Generic;
1110
using System.Linq;
@@ -15,7 +14,7 @@
1514
using System.Data.Entity;
1615
using System.Runtime.Caching;
1716

18-
#elif EF7
17+
#elif EFCORE
1918
using Microsoft.Data.Entity;
2019
using Microsoft.Extensions.Caching.Memory;
2120

@@ -107,7 +106,7 @@ public static Task<IEnumerable<T>> FromCacheAsync<T>(this IQueryable<T> query, p
107106
{
108107
return query.FromCacheAsync(QueryCacheManager.DefaultCacheItemPolicy, tags);
109108
}
110-
#elif EF7
109+
#elif EFCORE
111110
/// <summary>
112111
/// Return the result of the <paramref name="query" /> from the cache. If the query is not cached
113112
/// yet, the query is materialized and cached before being returned.

src/Z.EntityFramework.Plus.EF5.NET40/QueryCache/Extensions/QueryDeferred`/FromCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System;
1010
using System.Runtime.Caching;
1111

12-
#elif EF7
12+
#elif EFCORE
1313
using Microsoft.Extensions.Caching.Memory;
1414

1515
#endif
@@ -90,7 +90,7 @@ public static T FromCache<T>(this QueryDeferred<T> query, params string[] tags)
9090
{
9191
return query.FromCache(QueryCacheManager.DefaultCacheItemPolicy, tags);
9292
}
93-
#elif EF7
93+
#elif EFCORE
9494
/// <summary>
9595
/// Return the result of the <paramref name="query" /> from the cache. If the query is not cached
9696
/// yet, the query is materialized asynchronously and cached before being returned.

src/Z.EntityFramework.Plus.EF5.NET40/QueryCache/Extensions/QueryDeferred`/FromCacheAsync.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
// More projects: http://www.zzzprojects.com/
66
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
77

8-
98
#if NET45
109
using System.Threading.Tasks;
1110
#if EF5 || EF6
1211
using System;
1312
using System.Runtime.Caching;
1413

15-
#elif EF7
14+
#elif EFCORE
1615
using Microsoft.Extensions.Caching.Memory;
1716

1817
#endif
@@ -103,7 +102,7 @@ public static Task<T> FromCacheAsync<T>(this QueryDeferred<T> query, params stri
103102
{
104103
return query.FromCacheAsync(QueryCacheManager.DefaultCacheItemPolicy, tags);
105104
}
106-
#elif EF7
105+
#elif EFCORE
107106
/// <summary>
108107
/// Return the result of the <paramref name="query" /> from the cache. If the query is not cached
109108
/// yet, the query is materialized and cached before being returned.

src/Z.EntityFramework.Plus.EF5.NET40/QueryCache/QueryCacheManager.cs

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
using System.Collections.Concurrent;
99
using System.Collections.Generic;
1010
using System.Linq;
11+
using System.Text;
1112
#if EF5 || EF6
1213
using System.Runtime.Caching;
1314

14-
#elif EF7
15+
#elif EFCORE
1516
using Microsoft.Extensions.Caching.Memory;
1617

1718
#endif
@@ -27,7 +28,7 @@ static QueryCacheManager()
2728
#if EF5 || EF6
2829
Cache = MemoryCache.Default;
2930
DefaultCacheItemPolicy = new CacheItemPolicy();
30-
#elif EF7
31+
#elif EFCORE
3132
Cache = new MemoryCache(new MemoryCacheOptions());
3233
DefaultMemoryCacheEntryOptions = new MemoryCacheEntryOptions();
3334
#endif
@@ -36,16 +37,16 @@ static QueryCacheManager()
3637
}
3738

3839
#if EF5 || EF6
39-
/// <summary>Gets or sets the cache to use for QueryCacheExtensions extension methods.</summary>
40-
/// <value>The cache to use for QueryCacheExtensions extension methods.</value>
40+
/// <summary>Gets or sets the cache to use for QueryCacheExtensions extension methods.</summary>
41+
/// <value>The cache to use for QueryCacheExtensions extension methods.</value>
4142
public static ObjectCache Cache { get; set; }
4243

4344
/// <summary>Gets or sets the default cache item policy to use when no policy is specified.</summary>
4445
/// <value>The default cache item policy to use when no policy is specified.</value>
4546
public static CacheItemPolicy DefaultCacheItemPolicy { get; set; }
46-
#elif EF7
47-
/// <summary>Gets or sets the cache to use for the QueryCacheExtensions extension methods.</summary>
48-
/// <value>The cache to use for the QueryCacheExtensions extension methods.</value>
47+
#elif EFCORE
48+
/// <summary>Gets or sets the cache to use for the QueryCacheExtensions extension methods.</summary>
49+
/// <value>The cache to use for the QueryCacheExtensions extension methods.</value>
4950
public static IMemoryCache Cache { get; set; }
5051

5152
/// <summary>Gets or sets the default memory cache entry options to use when no policy is specified.</summary>
@@ -104,19 +105,83 @@ public static void ExpireTag(params string[] tags)
104105
/// <param name="query">The query to cache or retrieve from the QueryCacheManager.</param>
105106
/// <param name="tags">A variable-length parameters list containing tags to create the cache key.</param>
106107
/// <returns>The cache key used to cache or retrieve a query from the QueryCacheManager.</returns>
107-
internal static string GetCacheKey(IQueryable query, string[] tags)
108+
public static string GetCacheKey(IQueryable query, string[] tags)
108109
{
109-
return CachePrefix + string.Join(";", tags) + query;
110+
var sb = new StringBuilder();
111+
112+
#if EF5 || EF6
113+
var objectQuery = query.GetObjectQuery();
114+
115+
sb.AppendLine(CachePrefix);
116+
sb.AppendLine(string.Join(";", tags));
117+
sb.AppendLine(objectQuery.ToTraceString());
118+
119+
foreach (var parameter in objectQuery.Parameters)
120+
{
121+
sb.Append(parameter.Name);
122+
sb.Append(";");
123+
sb.Append(parameter.Value);
124+
sb.AppendLine(";");
125+
}
126+
#elif EFCORE
127+
var command = query.CreateCommand();
128+
129+
sb.AppendLine(CachePrefix);
130+
sb.AppendLine(string.Join(";", tags));
131+
sb.AppendLine(command.CommandText);
132+
133+
foreach (var parameter in command.Parameters)
134+
{
135+
sb.Append(parameter.Name);
136+
sb.Append(";");
137+
sb.Append(parameter.Value);
138+
sb.AppendLine(";");
139+
}
140+
#endif
141+
142+
return sb.ToString();
110143
}
111144

112145
/// <summary>Gets cached keys used to cache or retrieve a query from the QueryCacheManager.</summary>
113146
/// <typeparam name="T">Generic type parameter.</typeparam>
114147
/// <param name="query">The query to cache or retrieve from the QueryCacheManager.</param>
115148
/// <param name="tags">A variable-length parameters list containing tags to create the cache key.</param>
116149
/// <returns>The cache key used to cache or retrieve a query from the QueryCacheManager.</returns>
117-
internal static string GetCacheKey<T>(QueryDeferred<T> query, string[] tags)
150+
public static string GetCacheKey<T>(QueryDeferred<T> query, string[] tags)
118151
{
119-
return CachePrefix + string.Join(";", tags) + query.Query.Expression;
152+
var sb = new StringBuilder();
153+
154+
#if EF5 || EF6
155+
var objectQuery = query.Query.GetObjectQuery();
156+
157+
sb.AppendLine(CachePrefix);
158+
sb.AppendLine(string.Join(";", tags));
159+
sb.AppendLine(objectQuery.ToTraceString());
160+
161+
foreach (var parameter in objectQuery.Parameters)
162+
{
163+
sb.Append(parameter.Name);
164+
sb.Append(";");
165+
sb.Append(parameter.Value);
166+
sb.AppendLine(";");
167+
}
168+
#elif EFCORE
169+
var command = query.Query.CreateCommand();
170+
171+
sb.AppendLine(CachePrefix);
172+
sb.AppendLine(string.Join(";", tags));
173+
sb.AppendLine(command.CommandText);
174+
175+
foreach (var parameter in command.Parameters)
176+
{
177+
sb.Append(parameter.Name);
178+
sb.Append(";");
179+
sb.Append(parameter.Value);
180+
sb.AppendLine(";");
181+
}
182+
#endif
183+
184+
return sb.ToString();
120185
}
121186
}
122187
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 STANDALONE
9+
#if EFCORE
10+
using System.Linq;
11+
using System.Reflection;
12+
using Microsoft.Data.Entity.Query;
13+
using Microsoft.Data.Entity.Query.ExpressionVisitors.Internal;
14+
using Microsoft.Data.Entity.Query.Internal;
15+
using Microsoft.Data.Entity.Storage;
16+
using Remotion.Linq.Parsing.ExpressionVisitors.TreeEvaluation;
17+
using Remotion.Linq.Parsing.Structure;
18+
19+
namespace Z.EntityFramework.Plus
20+
{
21+
public static partial class Extensions
22+
{
23+
public static IRelationalCommand CreateCommand<T>(this IQueryable<T> source)
24+
{
25+
var compilerField = typeof (EntityQueryProvider).GetField("_queryCompiler", BindingFlags.NonPublic | BindingFlags.Instance);
26+
var compiler = compilerField.GetValue(source.Provider);
27+
28+
var queryContextFactoryField = compiler.GetType().GetField("_queryContextFactory", BindingFlags.NonPublic | BindingFlags.Instance);
29+
var queryContextFactory = (IQueryContextFactory) queryContextFactoryField.GetValue(compiler);
30+
31+
var queryContext = queryContextFactory.Create();
32+
33+
var evalutableExpressionFilterField = compiler.GetType().GetField("_evaluatableExpressionFilter", BindingFlags.NonPublic | BindingFlags.Static);
34+
var evalutableExpressionFilter = (IEvaluatableExpressionFilter) evalutableExpressionFilterField.GetValue(null);
35+
36+
var query = new QueryAnnotatingExpressionVisitor().Visit(source.Expression);
37+
var newQuery = ParameterExtractingExpressionVisitor.ExtractParameters(query, queryContext, evalutableExpressionFilter);
38+
39+
var queryParserMethod = compiler.GetType().GetMethod("CreateQueryParser", BindingFlags.NonPublic | BindingFlags.Static);
40+
var queryparser = (QueryParser) queryParserMethod.Invoke(null, new object[0]);
41+
var queryModel = queryparser.GetParsedQuery(newQuery);
42+
43+
var databaseField = compiler.GetType().GetField("_database", BindingFlags.NonPublic | BindingFlags.Instance);
44+
var database = (IDatabase) databaseField.GetValue(compiler);
45+
46+
var queryCompilationContextFactoryField = typeof (Database).GetField("_queryCompilationContextFactory", BindingFlags.NonPublic | BindingFlags.Instance);
47+
var queryCompilationContextFactory = (IQueryCompilationContextFactory) queryCompilationContextFactoryField.GetValue(database);
48+
49+
var queryModelVisitor = (RelationalQueryModelVisitor) queryCompilationContextFactory.Create(false).CreateQueryModelVisitor();
50+
var executor = queryModelVisitor.CreateQueryExecutor<T>(queryModel);
51+
52+
var queries = queryModelVisitor.Queries;
53+
var sqlQuery = queries.ToList()[0];
54+
55+
var command = sqlQuery.CreateGenerator().GenerateSql(queryContext.ParameterValues);
56+
57+
return command;
58+
}
59+
60+
public static IRelationalCommand CreateCommand(this IQueryable source)
61+
{
62+
var compilerField = typeof (EntityQueryProvider).GetField("_queryCompiler", BindingFlags.NonPublic | BindingFlags.Instance);
63+
var compiler = compilerField.GetValue(source.Provider);
64+
65+
var queryContextFactoryField = compiler.GetType().GetField("_queryContextFactory", BindingFlags.NonPublic | BindingFlags.Instance);
66+
var queryContextFactory = (IQueryContextFactory) queryContextFactoryField.GetValue(compiler);
67+
68+
var queryContext = queryContextFactory.Create();
69+
70+
var evalutableExpressionFilterField = compiler.GetType().GetField("_evaluatableExpressionFilter", BindingFlags.NonPublic | BindingFlags.Static);
71+
var evalutableExpressionFilter = (IEvaluatableExpressionFilter) evalutableExpressionFilterField.GetValue(null);
72+
73+
var query = new QueryAnnotatingExpressionVisitor().Visit(source.Expression);
74+
var newQuery = ParameterExtractingExpressionVisitor.ExtractParameters(query, queryContext, evalutableExpressionFilter);
75+
76+
var queryParserMethod = compiler.GetType().GetMethod("CreateQueryParser", BindingFlags.NonPublic | BindingFlags.Static);
77+
var queryparser = (QueryParser) queryParserMethod.Invoke(null, new object[0]);
78+
var queryModel = queryparser.GetParsedQuery(newQuery);
79+
80+
var databaseField = compiler.GetType().GetField("_database", BindingFlags.NonPublic | BindingFlags.Instance);
81+
var database = (IDatabase) databaseField.GetValue(compiler);
82+
83+
var queryCompilationContextFactoryField = typeof (Database).GetField("_queryCompilationContextFactory", BindingFlags.NonPublic | BindingFlags.Instance);
84+
var queryCompilationContextFactory = (IQueryCompilationContextFactory) queryCompilationContextFactoryField.GetValue(database);
85+
86+
var queryModelVisitor = (RelationalQueryModelVisitor) queryCompilationContextFactory.Create(false).CreateQueryModelVisitor();
87+
var createQueryExecutorMethod = queryModelVisitor.GetType().GetMethod("CreateQueryExecutor");
88+
var createQueryExecutorMethodGeneric = createQueryExecutorMethod.MakeGenericMethod(source.ElementType);
89+
createQueryExecutorMethodGeneric.Invoke(queryModelVisitor, new[] {queryModel});
90+
91+
var queries = queryModelVisitor.Queries;
92+
var sqlQuery = queries.ToList()[0];
93+
94+
95+
var command = sqlQuery.CreateGenerator().GenerateSql(queryContext.ParameterValues);
96+
97+
return command;
98+
}
99+
}
100+
}
101+
102+
#endif
103+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 STANDALONE
9+
namespace Z.EntityFramework.Plus
10+
{
11+
internal class ExceptionMessage
12+
{
13+
public static string GeneralException = "Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]";
14+
}
15+
}
16+
#endif

0 commit comments

Comments
 (0)