Skip to content

Commit c932adb

Browse files
author
zzzprojects
committed
Update audit to v1.0.1 + adding support to async provider (v1.0.2)
Update audit to v1.0.1 + adding support to async provider (v1.0.2)
1 parent 56bd2b4 commit c932adb

File tree

121 files changed

+3958
-849
lines changed

Some content is hidden

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

121 files changed

+3958
-849
lines changed

src/Z.EntityFramework.Plus.EF5.NET40/Audit/Audit/AuditEntityModified.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
// Copyright (c) 2016 ZZZ Projects. All rights reserved.
77

88
using System.Data.Common;
9+
using System.Linq;
10+
911
#if EF5
1012
using System.Data.Objects;
1113

1214
#elif EF6
1315
using System.Data.Entity.Core.Objects;
1416

1517
#elif EF7
18+
using Microsoft.Data.Entity;
1619
using Microsoft.Data.Entity.ChangeTracking;
1720

1821
#endif
@@ -36,7 +39,7 @@ public static void AuditEntityModified(Audit audit, EntityEntry objectStateEntry
3639
};
3740

3841
#if EF5 || EF6
39-
AuditEntityModified(audit, entry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues);
42+
AuditEntityModified(audit, entry, objectStateEntry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues);
4043
#elif EF7
4144
AuditEntityModified(audit, entry, objectStateEntry);
4245
#endif
@@ -47,10 +50,11 @@ public static void AuditEntityModified(Audit audit, EntityEntry objectStateEntry
4750
/// <summary>Audit entity modified.</summary>
4851
/// <param name="audit">The audit to use to add changes made to the context.</param>
4952
/// <param name="entry">The entry.</param>
53+
/// <param name="objectStateEntry">The object state entry.</param>
5054
/// <param name="orginalRecord">The orginal record.</param>
5155
/// <param name="currentRecord">The current record.</param>
5256
/// <param name="prefix">The prefix.</param>
53-
public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "")
57+
public static void AuditEntityModified(Audit audit, AuditEntry entry, ObjectStateEntry objectStateEntry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "")
5458
{
5559
for (var i = 0; i < orginalRecord.FieldCount; i++)
5660
{
@@ -62,11 +66,14 @@ public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataReco
6266
if (valueRecord != null)
6367
{
6468
// Complex Type
65-
AuditEntityModified(audit, entry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, "."));
69+
AuditEntityModified(audit, entry, objectStateEntry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, "."));
6670
}
71+
6772
else if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, name))
6873
{
69-
if (!audit.Configuration.IgnorePropertyUnchanged || !Equals(currentValue, originalValue))
74+
if (!audit.Configuration.IgnorePropertyUnchanged
75+
|| objectStateEntry.EntityKey.EntityKeyValues.Any(x => x.Key == name)
76+
|| !Equals(currentValue, originalValue))
7077
{
7178
entry.Properties.Add(new AuditEntryProperty(entry, string.Concat(prefix, name), originalValue, currentValue));
7279
}
@@ -84,7 +91,7 @@ public static void AuditEntityModified(Audit audit, AuditEntry entry, EntityEntr
8491

8592
if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name))
8693
{
87-
if (audit.Configuration.IgnorePropertyUnchanged || property.IsModified)
94+
if (audit.Configuration.IgnorePropertyUnchanged || property.Metadata.IsKey() || property.IsModified)
8895
{
8996
entry.Properties.Add(new AuditEntryProperty(entry, propertyEntry.Name, property.OriginalValue, property.CurrentValue));
9097
}

src/Z.EntityFramework.Plus.EF5.NET40/ExceptionMessage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ internal class ExceptionMessage
1111
{
1212
public static string GeneralException = "Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]";
1313
public static string QueryIncludeFilter_ArgumentExpression = "Oops! immediate method with expression argument are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";
14-
public static string QueryIncludeFilter_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter For more information, contact us: [email protected]";
14+
public static string QueryIncludeFilter_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";
15+
public static string QueryIncludeFilter_Include = "Oops! 'Include' method from Entity Framework is not supported, use only IncludeFilter method. For more information, contact us: [email protected]";
1516
public static string QueryIncludeOptimized_ArgumentExpression = "Oops! immediate method with expression argument are not supported. For more information, contact us: [email protected]";
1617
public static string QueryIncludeOptimized_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter For more information, contact us: [email protected]";
18+
public static string QueryIncludeOptimized_Include = "Oops! 'Include' method from Entity Framework is not supported, use only IncludeOptimized method. For more information, contact us: [email protected]";
1719
}
1820
}

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.0")]
22-
[assembly: AssemblyFileVersion("1.0.0")]
21+
[assembly: AssemblyVersion("1.0.2")]
22+
[assembly: AssemblyFileVersion("1.0.2")]

src/Z.EntityFramework.Plus.EF5.NET40/QueryIncludeOptimized/QueryIncludeOptimizedParentQueryable`.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,27 @@
1010
using System.Collections.Generic;
1111
using System.Linq;
1212
using System.Linq.Expressions;
13+
using System.Threading.Tasks;
1314
#if EF5
1415
using System.Data.Metadata.Edm;
1516

1617
#elif EF6
1718
using System.Data.Entity.Core.Metadata.Edm;
19+
#endif
20+
#if NET45
21+
using System.Data.Entity.Infrastructure;
1822

1923
#endif
2024

2125
namespace Z.EntityFramework.Plus
2226
{
2327
/// <summary>A class for query include optimized parent queryable.</summary>
2428
/// <typeparam name="T">The type of elements of the query.</typeparam>
29+
#if EF6 && NET45
30+
public class QueryIncludeOptimizedParentQueryable<T> : IOrderedQueryable<T>, IDbAsyncEnumerable<T>
31+
#else
2532
public class QueryIncludeOptimizedParentQueryable<T> : IOrderedQueryable<T>
33+
#endif
2634
{
2735
/// <summary>Constructor.</summary>
2836
/// <param name="query">The query parent.</param>
@@ -130,5 +138,30 @@ public void CreateQueryable(IQueryable<T> query)
130138
child.CreateIncludeQuery(query);
131139
}
132140
}
141+
142+
/// <summary>Includes the related entities path in the query.</summary>
143+
/// <param name="path">The related entities path in the query to include.</param>
144+
/// <returns>The new queryable.</returns>
145+
public IQueryable Include(string path)
146+
{
147+
throw new Exception(ExceptionMessage.QueryIncludeOptimized_Include);
148+
}
149+
150+
#if EF6 && NET45
151+
/// <summary>Gets the asynchrounously enumerator.</summary>
152+
/// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
153+
/// <returns>The asynchrounously enumerator.</returns>
154+
IDbAsyncEnumerator<T> IDbAsyncEnumerable<T>.GetAsyncEnumerator()
155+
{
156+
return new LazyAsyncEnumerator<T>(token => Task.Run(() => CreateEnumerable(), token));
157+
}
158+
159+
/// <summary>Gets the asynchrounously enumerator.</summary>
160+
/// <returns>The asynchrounously enumerator.</returns>
161+
public IDbAsyncEnumerator GetAsyncEnumerator()
162+
{
163+
return new LazyAsyncEnumerator<T>(token => Task.Run(() => CreateEnumerable(), token));
164+
}
165+
#endif
133166
}
134167
}

src/Z.EntityFramework.Plus.EF5.NET40/QueryIncludeOptimized/QueryIncludeOptimizedProvider.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Collections.Generic;
1010
using System.Linq.Expressions;
1111
using System.Reflection;
12+
using System.Threading;
13+
using System.Threading.Tasks;
1214
#if EF5
1315
using System.Data.Metadata.Edm;
1416
using System.Data.Objects;
@@ -18,18 +20,25 @@
1820
using System.Data.Entity.Core.Metadata.Edm;
1921
using System.Data.Entity.Core.Objects;
2022
using System.Linq;
21-
2223
#elif EF7
2324
using Microsoft.Data.Entity.Internal;
2425
using Microsoft.Data.Entity.Query.Internal;
2526
using Remotion.Linq;
2627

28+
#endif
29+
#if NET45
30+
using System.Data.Entity.Infrastructure;
31+
2732
#endif
2833

2934
namespace Z.EntityFramework.Plus
3035
{
3136
/// <summary>A class for query include optimized provider.</summary>
37+
#if EF6 && NET45
38+
public class QueryIncludeOptimizedProvider<T> : IDbAsyncQueryProvider
39+
#else
3240
public class QueryIncludeOptimizedProvider<T> : IQueryProvider
41+
#endif
3342
{
3443
/// <summary>Constructor.</summary>
3544
/// <param name="originalProvider">The original provider.</param>
@@ -199,5 +208,27 @@ public TResult Execute<TResult>(Expression expression)
199208
return (TResult)value;
200209
#endif
201210
}
211+
212+
#if EF6 && NET45
213+
/// <summary>Executes the given expression asynchronously.</summary>
214+
/// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
215+
/// <param name="expression">The expression to execute.</param>
216+
/// <param name="cancellationToken">The cancellation token.</param>
217+
/// <returns>The object returned by the execution of the expression.</returns>
218+
public Task<object> ExecuteAsync(Expression expression, CancellationToken cancellationToken)
219+
{
220+
throw new Exception(ExceptionMessage.GeneralException);
221+
}
222+
223+
/// <summary>Executes the given expression asynchronously.</summary>
224+
/// <typeparam name="TResult">Type of the result.</typeparam>
225+
/// <param name="expression">The expression to execute.</param>
226+
/// <param name="cancellationToken">The cancellation token.</param>
227+
/// <returns>The object returned by the execution of the expression.</returns>
228+
public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
229+
{
230+
return Task.Run(() => Execute<TResult>(expression), cancellationToken);
231+
}
232+
#endif
202233
}
203234
}

src/Z.EntityFramework.Plus.EF5.NET40/QueryIncludeOptimized/Standalone/ExceptionMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal class ExceptionMessage
1414
public static string GeneralException = "Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]";
1515
public static string QueryIncludeOptimized_ArgumentExpression = "Oops! immediate method with expression argument are not supported. For more information, contact us: [email protected]";
1616
public static string QueryIncludeOptimized_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter For more information, contact us: [email protected]";
17+
public static string QueryIncludeOptimized_Include = "Oops! 'Include' method from Entity Framework is not supported, use only IncludeOptimized method. For more information, contact us: [email protected]";
1718
}
1819
}
1920
#endif
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#if STANDALONE
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Data.Entity.Infrastructure;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
#if EF6 && NET45
10+
11+
namespace Z.EntityFramework.Plus
12+
{
13+
internal class LazyAsyncEnumerator<T> : IDbAsyncEnumerator<T>
14+
{
15+
private readonly Func<CancellationToken, Task<IEnumerable<T>>> _getObjectResultAsync;
16+
private IEnumerator<T> _objectResultAsyncEnumerator;
17+
18+
public LazyAsyncEnumerator(Func<CancellationToken, Task<IEnumerable<T>>> getObjectResultAsync)
19+
{
20+
_getObjectResultAsync = getObjectResultAsync;
21+
}
22+
23+
public T Current
24+
{
25+
get
26+
{
27+
return _objectResultAsyncEnumerator == null
28+
? default(T)
29+
: _objectResultAsyncEnumerator.Current;
30+
}
31+
}
32+
33+
object IDbAsyncEnumerator.Current
34+
{
35+
get { return Current; }
36+
}
37+
38+
public void Dispose()
39+
{
40+
if (_objectResultAsyncEnumerator != null)
41+
{
42+
_objectResultAsyncEnumerator.Dispose();
43+
}
44+
}
45+
46+
public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
47+
{
48+
cancellationToken.ThrowIfCancellationRequested();
49+
50+
if (_objectResultAsyncEnumerator != null)
51+
{
52+
return Task.FromResult(_objectResultAsyncEnumerator.MoveNext());
53+
}
54+
55+
return FirstMoveNextAsync(cancellationToken);
56+
}
57+
58+
private async Task<bool> FirstMoveNextAsync(CancellationToken cancellationToken)
59+
{
60+
var objectResult = await _getObjectResultAsync(cancellationToken).ConfigureAwait(false);
61+
try
62+
{
63+
_objectResultAsyncEnumerator = objectResult.GetEnumerator();
64+
}
65+
catch
66+
{
67+
throw;
68+
}
69+
return _objectResultAsyncEnumerator.MoveNext();
70+
}
71+
}
72+
}
73+
74+
#endif
75+
#endif

src/Z.EntityFramework.Plus.EF5.NET40/Z.EntityFramework.Plus.EF5.NET40.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<Compile Include="QueryIncludeOptimized\QueryIncludeOptimizedParentQueryable`.cs" />
199199
<Compile Include="QueryIncludeOptimized\QueryIncludeOptimizedProvider.cs" />
200200
<Compile Include="QueryIncludeOptimized\Standalone\ExceptionMessage.cs" />
201+
<Compile Include="QueryIncludeOptimized\Standalone\LazyAsyncEnumerator\LazyAsyncEnumerator.cs" />
201202
<Compile Include="QueryIncludeOptimized\Standalone\QueryAddOrAppendOrder\Extensions\IQueryable`.AddToRootOrAppendOrderBy.cs" />
202203
<Compile Include="QueryIncludeOptimized\Standalone\QueryAddOrAppendOrder\QueryAddOrAppendOrderExpressionVisitor`.cs" />
203204
<Compile Include="QueryIncludeOptimized\Standalone\QueryFuture\QueryFuture\BaseQueryFuture.cs" />

src/Z.EntityFramework.Plus.EF5/Audit/Audit/AuditEntityModified.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
// Copyright (c) 2016 ZZZ Projects. All rights reserved.
77

88
using System.Data.Common;
9+
using System.Linq;
10+
911
#if EF5
1012
using System.Data.Objects;
1113

1214
#elif EF6
1315
using System.Data.Entity.Core.Objects;
1416

1517
#elif EF7
18+
using Microsoft.Data.Entity;
1619
using Microsoft.Data.Entity.ChangeTracking;
1720

1821
#endif
@@ -36,7 +39,7 @@ public static void AuditEntityModified(Audit audit, EntityEntry objectStateEntry
3639
};
3740

3841
#if EF5 || EF6
39-
AuditEntityModified(audit, entry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues);
42+
AuditEntityModified(audit, entry, objectStateEntry, objectStateEntry.OriginalValues, objectStateEntry.CurrentValues);
4043
#elif EF7
4144
AuditEntityModified(audit, entry, objectStateEntry);
4245
#endif
@@ -47,10 +50,11 @@ public static void AuditEntityModified(Audit audit, EntityEntry objectStateEntry
4750
/// <summary>Audit entity modified.</summary>
4851
/// <param name="audit">The audit to use to add changes made to the context.</param>
4952
/// <param name="entry">The entry.</param>
53+
/// <param name="objectStateEntry">The object state entry.</param>
5054
/// <param name="orginalRecord">The orginal record.</param>
5155
/// <param name="currentRecord">The current record.</param>
5256
/// <param name="prefix">The prefix.</param>
53-
public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "")
57+
public static void AuditEntityModified(Audit audit, AuditEntry entry, ObjectStateEntry objectStateEntry, DbDataRecord orginalRecord, DbUpdatableDataRecord currentRecord, string prefix = "")
5458
{
5559
for (var i = 0; i < orginalRecord.FieldCount; i++)
5660
{
@@ -62,11 +66,14 @@ public static void AuditEntityModified(Audit audit, AuditEntry entry, DbDataReco
6266
if (valueRecord != null)
6367
{
6468
// Complex Type
65-
AuditEntityModified(audit, entry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, "."));
69+
AuditEntityModified(audit, entry, objectStateEntry, valueRecord, currentValue as DbUpdatableDataRecord, string.Concat(prefix, name, "."));
6670
}
71+
6772
else if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, name))
6873
{
69-
if (!audit.Configuration.IgnorePropertyUnchanged || !Equals(currentValue, originalValue))
74+
if (!audit.Configuration.IgnorePropertyUnchanged
75+
|| objectStateEntry.EntityKey.EntityKeyValues.Any(x => x.Key == name)
76+
|| !Equals(currentValue, originalValue))
7077
{
7178
entry.Properties.Add(new AuditEntryProperty(entry, string.Concat(prefix, name), originalValue, currentValue));
7279
}
@@ -84,7 +91,7 @@ public static void AuditEntityModified(Audit audit, AuditEntry entry, EntityEntr
8491

8592
if (entry.Parent.CurrentOrDefaultConfiguration.IsAuditedProperty(entry.Entry, propertyEntry.Name))
8693
{
87-
if (audit.Configuration.IgnorePropertyUnchanged || property.IsModified)
94+
if (audit.Configuration.IgnorePropertyUnchanged || property.Metadata.IsKey() || property.IsModified)
8895
{
8996
entry.Properties.Add(new AuditEntryProperty(entry, propertyEntry.Name, property.OriginalValue, property.CurrentValue));
9097
}

src/Z.EntityFramework.Plus.EF5/ExceptionMessage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ internal class ExceptionMessage
1111
{
1212
public static string GeneralException = "Oops! A general error has occurred. Please report the issue including the stack trace to our support team: [email protected]";
1313
public static string QueryIncludeFilter_ArgumentExpression = "Oops! immediate method with expression argument are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";
14-
public static string QueryIncludeFilter_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter For more information, contact us: [email protected]";
14+
public static string QueryIncludeFilter_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter. For more information, contact us: [email protected]";
15+
public static string QueryIncludeFilter_Include = "Oops! 'Include' method from Entity Framework is not supported, use only IncludeFilter method. For more information, contact us: [email protected]";
1516
public static string QueryIncludeOptimized_ArgumentExpression = "Oops! immediate method with expression argument are not supported. For more information, contact us: [email protected]";
1617
public static string QueryIncludeOptimized_CreateQueryElement = "Oops! Select projection are not supported in EF+ Query IncludeFilter For more information, contact us: [email protected]";
18+
public static string QueryIncludeOptimized_Include = "Oops! 'Include' method from Entity Framework is not supported, use only IncludeOptimized method. For more information, contact us: [email protected]";
1719
}
1820
}

0 commit comments

Comments
 (0)