Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
839ea09
upgrade to EF6
pwelter34 Oct 22, 2013
0793a0a
- update to EF6
pwelter34 Oct 22, 2013
4f070e8
update entities
pwelter34 Oct 22, 2013
62b2b04
update package
pwelter34 Oct 22, 2013
3b62f90
- convert to nunit
pwelter34 Oct 22, 2013
f4aadf9
Adding async support
taschmidt Nov 12, 2013
7a989ce
Change FromCache to return an IList instead of IEnumerable
taschmidt Nov 13, 2013
543bb51
- add DataContract attributes
Jan 24, 2014
f2e635b
fix build
Jan 24, 2014
2281b3a
Projects are upgraded to EF 6.1 and compatibility issues are fixed.
Mar 18, 2014
f86f7eb
code formatting: spaces are restored
Mar 18, 2014
2aa5c3c
Merge pull request #75 from taschmidt/master
pwelter34 Mar 20, 2014
387477e
Merge pull request #88 from StasPerekrestov/master
pwelter34 Mar 20, 2014
1f830c6
EF 6.1 support
Mar 23, 2014
2a999b9
fix build
Mar 23, 2014
6129ef8
add new Metadata mapping
Apr 21, 2014
8ae1c79
try to fix test
Apr 21, 2014
e06943f
Handle inheritance when determining mapping
ocdi Apr 23, 2014
2219133
Merge pull request #96 from ocdi/master
pwelter34 Apr 23, 2014
283caae
Fixed audit not always setting correct display value for optional rel…
wimr Aug 13, 2014
46853ee
Merge pull request #120 from wimr/master
pwelter34 Aug 13, 2014
bc206f3
Merge pull request #1 from loresoft/master
wimr Aug 25, 2014
a5f4df4
fix for issue #123: Auditlogger gives nullreference exception when tr…
wimr Aug 25, 2014
42a5266
Merge pull request #124 from wimr/master
pwelter34 Aug 27, 2014
5eaa3ad
refactor for new build
pwelter34 Aug 28, 2014
3744c09
tweak build
pwelter34 Aug 28, 2014
e3a0f79
tweak build
pwelter34 Sep 2, 2014
d7a6989
more build work
pwelter34 Sep 2, 2014
739ab37
fix xunit runner
pwelter34 Sep 2, 2014
8e2fccf
restore database on build
pwelter34 Sep 2, 2014
fc8d2f2
add all tests to build
pwelter34 Sep 2, 2014
d675db9
fix sql ddl restore
pwelter34 Sep 2, 2014
6eab682
build changes
pwelter34 Sep 3, 2014
58b7452
update build script to use sql 2014
Sep 3, 2014
a3e8a55
change when sql database is restored
Sep 3, 2014
0d2a5f3
- cleanup project
Sep 3, 2014
52f7eed
tweak unit testing
Sep 3, 2014
54161b0
more build tweaks
Sep 4, 2014
6d5966a
use SqlPackage to restore database
Sep 4, 2014
e2814c2
update connection string
Sep 4, 2014
428401a
fix tests
Sep 4, 2014
d2f2487
fix async issue
pwelter34 Sep 12, 2014
bb24f01
add IncludeInserts and IncludeDeletes to logging Configuration
pwelter34 Jan 5, 2015
244e468
fix failing test
pwelter34 Jan 5, 2015
0f4eab3
more test fixes
pwelter34 Jan 5, 2015
26f23b8
test fix
pwelter34 Jan 5, 2015
ef14ba4
disable test
pwelter34 Jan 6, 2015
29d5807
Clear Cache
PatelVish Jan 30, 2015
c7577ef
fix future queries running under transaction
DzheiZee Mar 18, 2015
0c7ff8a
Fix Bug "Sequence Contains More Than One Element"
acymiranda Mar 18, 2015
d6a563a
Revert "Fix Bug "Sequence Contains More Than One Element""
acymiranda Mar 18, 2015
950b0c3
Fix bug “Sequence contains more than one element” #101
acymiranda Mar 18, 2015
569128a
Merge pull request #156 from acymiranda/master
pwelter34 Mar 19, 2015
81ff0b2
Merge pull request #155 from DzheiZee/master
pwelter34 Mar 19, 2015
af32558
Merge pull request #146 from PatelVish/master
pwelter34 Mar 19, 2015
9772c75
updated nuget badge icons
pwelter34 Mar 22, 2015
3fd30ac
Fix bug "Delete with multiple EDMX"
acymiranda Mar 27, 2015
9cae97a
Merge pull request #157 from acymiranda/master
pwelter34 Mar 27, 2015
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
Prev Previous commit
Next Next commit
Adding async support
  • Loading branch information
taschmidt committed Nov 12, 2013
commit f4aadf919b57c7e9da6f9748408877a32ba1947a
24 changes: 24 additions & 0 deletions Source/EntityFramework.Extended/Batch/IBatchRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data.Entity.Core.Objects;
using System.Linq.Expressions;
using System.Threading.Tasks;
using EntityFramework.Mapping;

namespace EntityFramework.Batch
Expand All @@ -22,6 +23,17 @@ public interface IBatchRunner
int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query)
where TEntity : class;

/// <summary>
/// Create and runs a batch delete statement asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="objectContext">The <see cref="ObjectContext"/> to get connection and metadata information from.</param>
/// <param name="entityMap">The <see cref="EntityMap"/> for <typeparamref name="TEntity"/>.</param>
/// <param name="query">The query to create the where clause from.</param>
/// <returns>The number of rows deleted.</returns>
Task<int> DeleteAsync<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query)
where TEntity : class;

/// <summary>
/// Create and runs a batch update statement.
/// </summary>
Expand All @@ -33,5 +45,17 @@ int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuer
/// <returns>The number of rows updated.</returns>
int Update<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression)
where TEntity : class;

/// <summary>
/// Create and runs a batch update statement asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="objectContext">The <see cref="ObjectContext"/> to get connection and metadata information from.</param>
/// <param name="entityMap">The <see cref="EntityMap"/> for <typeparamref name="TEntity"/>.</param>
/// <param name="query">The query to create the where clause from.</param>
/// <param name="updateExpression">The update expression.</param>
/// <returns>The number of rows updated.</returns>
Task<int> UpdateAsync<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression)
where TEntity : class;
}
}
54 changes: 50 additions & 4 deletions Source/EntityFramework.Extended/Batch/SqlServerBatchRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using EntityFramework.Extensions;
using EntityFramework.Mapping;
using EntityFramework.Reflection;
Expand All @@ -29,7 +30,27 @@ public class SqlServerBatchRunner : IBatchRunner
/// <returns>
/// The number of rows deleted.
/// </returns>
public int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query)
public int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query) where TEntity : class
{
return InternalDelete(objectContext, entityMap, query, false).Result;
}

/// <summary>
/// Create and run a batch delete statement asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="objectContext">The <see cref="ObjectContext"/> to get connection and metadata information from.</param>
/// <param name="entityMap">The <see cref="EntityMap"/> for <typeparamref name="TEntity"/>.</param>
/// <param name="query">The query to create the where clause from.</param>
/// <returns>
/// The number of rows deleted.
/// </returns>
public Task<int> DeleteAsync<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query) where TEntity : class
{
return InternalDelete(objectContext, entityMap, query, true);
}

private async Task<int> InternalDelete<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, bool async = false)
where TEntity : class
{
DbConnection deleteConnection = null;
Expand Down Expand Up @@ -89,7 +110,9 @@ public int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, Obj

deleteCommand.CommandText = sqlBuilder.ToString();

int result = deleteCommand.ExecuteNonQuery();
int result = async
? await deleteCommand.ExecuteNonQueryAsync()
: deleteCommand.ExecuteNonQuery();

// only commit if created transaction
if (ownTransaction)
Expand Down Expand Up @@ -121,7 +144,28 @@ public int Delete<TEntity>(ObjectContext objectContext, EntityMap entityMap, Obj
/// <returns>
/// The number of rows updated.
/// </returns>
public int Update<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression)
public int Update<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression) where TEntity : class
{
return InternalUpdate(objectContext, entityMap, query, updateExpression, false).Result;
}

/// <summary>
/// Create and run a batch update statement asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="objectContext">The <see cref="ObjectContext"/> to get connection and metadata information from.</param>
/// <param name="entityMap">The <see cref="EntityMap"/> for <typeparamref name="TEntity"/>.</param>
/// <param name="query">The query to create the where clause from.</param>
/// <param name="updateExpression">The update expression.</param>
/// <returns>
/// The number of rows updated.
/// </returns>
public Task<int> UpdateAsync<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression) where TEntity : class
{
return InternalUpdate(objectContext, entityMap, query, updateExpression, true);
}

private async Task<int> InternalUpdate<TEntity>(ObjectContext objectContext, EntityMap entityMap, ObjectQuery<TEntity> query, Expression<Func<TEntity, TEntity>> updateExpression, bool async = false)
where TEntity : class
{
DbConnection updateConnection = null;
Expand Down Expand Up @@ -297,7 +341,9 @@ public int Update<TEntity>(ObjectContext objectContext, EntityMap entityMap, Obj

updateCommand.CommandText = sqlBuilder.ToString();

int result = updateCommand.ExecuteNonQuery();
int result = async
? await updateCommand.ExecuteNonQueryAsync()
: updateCommand.ExecuteNonQuery();

// only commit if created transaction
if (ownTransaction)
Expand Down
18 changes: 18 additions & 0 deletions Source/EntityFramework.Extended/Caching/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityFramework.Caching
{
Expand Down Expand Up @@ -285,6 +286,23 @@ public virtual object GetOrAdd(CacheKey cacheKey, Func<CacheKey, object> valueFa
return item;
}

/// <summary>
/// Gets the cache value for the specified key that is already in the dictionary or the new value for the key as returned asynchronously by <paramref name="valueFactory"/>.
/// </summary>
/// <param name="cacheKey">A unique identifier for the cache entry.</param>
/// <param name="valueFactory">The asynchronous function used to generate a value to insert into cache.</param>
/// <param name="cachePolicy">An object that contains eviction details for the cache entry.</param>
/// <returns>
/// The value for the key. This will be either the existing value for the key if the key is already in the dictionary,
/// or the new value for the key as returned by <paramref name="valueFactory"/> if the key was not in the dictionary.
/// </returns>
public virtual Task<object> GetOrAddAsync(CacheKey cacheKey, Func<CacheKey, Task<object>> valueFactory, CachePolicy cachePolicy)
{
var provider = ResolveProvider();
var item = provider.GetOrAddAsync(cacheKey, valueFactory, cachePolicy);

return item;
}

/// <summary>
/// Removes a cache entry from the cache.
Expand Down
13 changes: 13 additions & 0 deletions Source/EntityFramework.Extended/Caching/ICacheProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace EntityFramework.Caching
{
Expand Down Expand Up @@ -39,6 +40,18 @@ public interface ICacheProvider
/// </returns>
object GetOrAdd(CacheKey cacheKey, Func<CacheKey, object> valueFactory, CachePolicy cachePolicy);

/// <summary>
/// Gets the cache value for the specified key that is already in the dictionary or the new value for the key as returned asynchronously by <paramref name="valueFactory"/>.
/// </summary>
/// <param name="cacheKey">A unique identifier for the cache entry.</param>
/// <param name="valueFactory">The asynchronous function used to generate a value to insert into cache.</param>
/// <param name="cachePolicy">A <see cref="CachePolicy"/> that contains eviction details for the cache entry.</param>
/// <returns>
/// The value for the key. This will be either the existing value for the key if the key is already in the cache,
/// or the new value for the key as returned by <paramref name="valueFactory"/> if the key was not in the cache.
/// </returns>
Task<object> GetOrAddAsync(CacheKey cacheKey, Func<CacheKey, Task<object>> valueFactory, CachePolicy cachePolicy);

/// <summary>
/// Removes a cache entry from the cache.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions Source/EntityFramework.Extended/Caching/MemoryCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Linq;
using System.Runtime.Caching;
using System.Threading.Tasks;

namespace EntityFramework.Caching
{
Expand Down Expand Up @@ -76,6 +77,37 @@ public object GetOrAdd(CacheKey cacheKey, Func<CacheKey, object> valueFactory, C
return value;
}

/// <summary>
/// Gets the cache value for the specified key that is already in the dictionary or the new value for the key as returned asynchronously by <paramref name="valueFactory"/>.
/// </summary>
/// <param name="cacheKey">A unique identifier for the cache entry.</param>
/// <param name="valueFactory">The asynchronous function used to generate a value to insert into cache.</param>
/// <param name="cachePolicy">A <see cref="CachePolicy"/> that contains eviction details for the cache entry.</param>
/// <returns>
/// The value for the key. This will be either the existing value for the key if the key is already in the cache,
/// or the new value for the key as returned by <paramref name="valueFactory"/> if the key was not in the cache.
/// </returns>
public async Task<object> GetOrAddAsync(CacheKey cacheKey, Func<CacheKey, Task<object>> valueFactory, CachePolicy cachePolicy)
{
var key = GetKey(cacheKey);
var cachedResult = MemoryCache.Default.Get(key);

if (cachedResult != null)
{
Debug.WriteLine("Cache Hit : " + key);
return cachedResult;
}

Debug.WriteLine("Cache Miss: " + key);

// get value and add to cache, not bothered
// if it succeeds or not just rerturn the value
var value = await valueFactory(cacheKey);
this.Add(cacheKey, value, cachePolicy);

return value;
}

/// <summary>
/// Removes a cache entry from the cache.
/// </summary>
Expand Down
Loading