Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #133. Compatibility for custom IDbSet<> #134 #135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletions Source/EntityFramework.Extended/Caching/Query/Evaluator.cs

This file was deleted.

This file was deleted.

38 changes: 5 additions & 33 deletions Source/EntityFramework.Extended/Caching/Query/QueryCache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq;
using EntityFramework.Extensions;

namespace EntityFramework.Caching
{
Expand All @@ -20,43 +19,16 @@ public static class QueryCache
/// </summary>
/// <param name="query">The query to get the key from.</param>
/// <returns>A unique key for the specified <see cref="IQueryable"/></returns>
public static string GetCacheKey(this IQueryable query)
public static string GetCacheKey<TEntity>(this IQueryable<TEntity> query) where TEntity : class
{
var expression = query.Expression;

// locally evaluate as much of the query as possible
expression = Evaluator.PartialEval(expression, QueryCache.CanBeEvaluatedLocally);

// support local collections
expression = LocalCollectionExpander.Rewrite(expression);

// use the string representation of the expression for the cache key
string key = expression.ToString();
// The key is made up of the SQL that will be executed, along with any parameters and their values
string key = query.ToTraceString();

// the key is potentially very long, so use an md5 fingerprint
// (fine if the query result data isn't critically sensitive)
key = key.ToMd5Fingerprint();

return key;
}

static Func<Expression, bool> CanBeEvaluatedLocally
{
get
{
return expression =>
{
// don't evaluate parameters
if (expression.NodeType == ExpressionType.Parameter)
return false;

// can't evaluate queries
if (typeof(IQueryable).IsAssignableFrom(expression.Type))
return false;

return true;
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@
<Compile Include="Caching\ICacheProvider.cs" />
<Compile Include="Caching\CacheTag.cs" />
<Compile Include="Caching\MemoryCacheProvider.cs" />
<Compile Include="Caching\Query\Evaluator.cs" />
<Compile Include="Caching\Query\LocalCollectionExpander.cs" />
<Compile Include="Caching\Query\QueryCache.cs" />
<Compile Include="Caching\Query\Utility.cs" />
<Compile Include="Future\IFutureRunner.cs" />
Expand Down Expand Up @@ -152,7 +150,6 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@
<Compile Include="Caching\ICacheProvider.cs" />
<Compile Include="Caching\CacheTag.cs" />
<Compile Include="Caching\MemoryCacheProvider.cs" />
<Compile Include="Caching\Query\Evaluator.cs" />
<Compile Include="Caching\Query\LocalCollectionExpander.cs" />
<Compile Include="Caching\Query\QueryCache.cs" />
<Compile Include="Caching\Query\Utility.cs" />
<Compile Include="Future\IFutureRunner.cs" />
Expand Down Expand Up @@ -152,7 +150,6 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Loading