Skip to content

Commit ab37deb

Browse files
author
zzzprojects
committed
Update to latest
Update to latest
1 parent 21d0536 commit ab37deb

File tree

73 files changed

+811
-160
lines changed

Some content is hidden

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

73 files changed

+811
-160
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public AuditConfiguration()
3232
{
3333
IgnorePropertyUnchanged = true;
3434

35-
EntityValueFormatters = new List<Func<object, string, Func<object, object>>>();
35+
EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>();
3636
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>();
3737
ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>();
3838

@@ -65,7 +65,7 @@ public AuditConfiguration()
6565

6666
/// <summary>Gets or sets a list of formatter for entity values.</summary>
6767
/// <value>A list of formatter for entity values.</value>
68-
public List<Func<object, string, Func<object, object>>> EntityValueFormatters { get; set; }
68+
public List<Func<object, string, object, Func<object, object>>> EntityValueFormatters { get; set; }
6969

7070
/// <summary>Gets or sets a list of predicates to exclude or include entities.</summary>
7171
/// <value>A list of predicates to exclude or include entities.</value>
@@ -151,7 +151,7 @@ public AuditConfiguration Clone()
151151
IgnorePropertyUnchanged = IgnorePropertyUnchanged,
152152
IgnoreRelationshipAdded = IgnoreRelationshipAdded,
153153
IgnoreRelationshipDeleted = IgnoreRelationshipDeleted,
154-
EntityValueFormatters = new List<Func<object, string, Func<object, object>>>(EntityValueFormatters),
154+
EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>(EntityValueFormatters),
155155
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>(ExcludeIncludeEntityPredicates),
156156
ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>(ExcludeIncludePropertyPredicates),
157157
SoftAddedPredicates = new List<Func<object, bool>>(SoftAddedPredicates),

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditConfiguration/Format.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public AuditConfiguration Format<T>(Expression<Func<T, object>> propertySelector
2727

2828
foreach (var accessor in propertyNames)
2929
{
30-
EntityValueFormatters.Add((x, s) => x is T && s == accessor ? formatter : null);
30+
EntityValueFormatters.Add((x, s, v) => x is T && s == accessor ? formatter : null);
3131
}
3232

3333
return this;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
using System;
9+
10+
namespace Z.EntityFramework.Plus
11+
{
12+
public partial class AuditConfiguration
13+
{
14+
public AuditConfiguration FormatType<T>(Func<T, object> formatter)
15+
{
16+
Func<object, object> func = o => formatter((T) o);
17+
18+
EntityValueFormatters.Add((x, s, v) => v != null && v.GetType() == typeof(T) ? func : null);
19+
20+
return this;
21+
}
22+
}
23+
}

src/Z.EntityFramework.Plus.EF5.NET40/Audit/AuditConfiguration/FormatValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class AuditConfiguration
3333
#if EF5 || EF6
3434
public string FormatValue(object entity, string propertyName, object currentValue)
3535
#elif EFCORE
36-
public string FormatValue(EntityEntry entry, string propertyName, object currentValue)
36+
public string FormatValue(object entity, string propertyName, object currentValue)
3737
#endif
3838
{
3939
if (EntityValueFormatters.Count > 0)
@@ -48,7 +48,7 @@ public string FormatValue(EntityEntry entry, string propertyName, object current
4848
{
4949
foreach (var formatProperty in EntityValueFormatters)
5050
{
51-
formatter = formatProperty(entity, propertyName);
51+
formatter = formatProperty(entity, propertyName, currentValue);
5252

5353
if (formatter != null)
5454
{

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

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ WHERE EXISTS ( SELECT 1 FROM ({Select}) AS B
5252
WHERE {PrimaryKeys}
5353
)
5454
";
55+
internal const string CommandTextOracleTemplate = @"
56+
DELETE
57+
FROM {TableName}
58+
WHERE EXISTS ( SELECT 1 FROM ({Select}) B
59+
WHERE {PrimaryKeys}
60+
)
61+
";
5562

5663
/// <summary>The command text postgre SQL template.</summary>
5764
internal const string CommandTextPostgreSQLTemplate = @"
@@ -199,6 +206,11 @@ public int Execute<T>(IQueryable<T> query) where T : class
199206
int totalRowAffecteds = command.ExecuteNonQuery();
200207
return totalRowAffecteds;
201208
}
209+
else if (command.Connection.GetType().Name.Contains("Oracle"))
210+
{
211+
int totalRowAffecteds = command.ExecuteNonQuery();
212+
return totalRowAffecteds;
213+
}
202214
else if (command.GetType().Name == "SqlCeCommand")
203215
{
204216
int totalRowAffecteds = command.ExecuteNonQuery();
@@ -301,6 +313,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
301313

302314
bool isMySql = command.GetType().FullName.Contains("MySql");
303315
var isSqlCe = command.GetType().Name == "SqlCeCommand";
316+
var isOracle = command.GetType().Namespace.Contains("Oracle");
304317

305318
// GET mapping
306319
var mapping = entity.Info.EntityTypeMapping.MappingFragment;
@@ -316,6 +329,12 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
316329
{
317330
tableName = string.Concat("[", store.Table, "]");
318331
}
332+
else if (isOracle)
333+
{
334+
tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" ?
335+
string.Concat("\"", store.Table, "\"") :
336+
string.Concat("\"", store.Schema, "\".\"", store.Table, "\"");
337+
}
319338
else
320339
{
321340
tableName = string.IsNullOrEmpty(store.Schema) ?
@@ -340,29 +359,31 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
340359
// GET command text template
341360
var commandTextTemplate = command.GetType().Name == "NpgsqlCommand" ?
342361
CommandTextPostgreSQLTemplate :
343-
isMySql ?
344-
CommandTextTemplate_MySql :
345-
isSqlCe ?
346-
CommandTextSqlCeTemplate :
347-
BatchSize > 0 ?
348-
BatchDelayInterval > 0 ?
349-
CommandTextWhileDelayTemplate :
350-
CommandTextWhileTemplate :
351-
CommandTextTemplate;
362+
isOracle ?
363+
CommandTextOracleTemplate :
364+
isMySql ?
365+
CommandTextTemplate_MySql :
366+
isSqlCe ?
367+
CommandTextSqlCeTemplate :
368+
BatchSize > 0 ?
369+
BatchDelayInterval > 0 ?
370+
CommandTextWhileDelayTemplate :
371+
CommandTextWhileTemplate :
372+
CommandTextTemplate;
352373

353374
// GET inner query
354375
var customQuery = query.GetCommandTextAndParameters();
355376
var querySelect = customQuery.Item1;
356377

357378
// GET primary key join
358379
string primaryKeys;
359-
if (isSqlCe)
380+
if (isSqlCe || isOracle)
360381
{
361-
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat(tableName + ".", EscapeName(x, isMySql), " = B.", EscapeName(x, isMySql), "")));
382+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat(tableName + ".", EscapeName(x, isMySql, isOracle), " = B.", EscapeName(x, isMySql, isOracle), "")));
362383
}
363384
else
364385
{
365-
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.", EscapeName(x, isMySql), " = B.", EscapeName(x, isMySql), "")));
386+
primaryKeys = string.Join(Environment.NewLine + "AND ", columnKeys.Select(x => string.Concat("A.", EscapeName(x, isMySql, isOracle), " = B.", EscapeName(x, isMySql, isOracle), "")));
366387
}
367388

368389
// REPLACE template
@@ -382,7 +403,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
382403
{
383404
var param = command.CreateParameter();
384405
param.ParameterName = parameter.Name;
385-
param.Value = parameter.Value;
406+
param.Value = parameter.Value ?? DBNull.Value;
386407

387408
command.Parameters.Add(param);
388409
}
@@ -391,7 +412,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
391412
{
392413
var param = command.CreateParameter();
393414
param.ParameterName = parameter.ParameterName;
394-
param.Value = parameter.Value;
415+
param.Value = parameter.Value ?? DBNull.Value;
395416

396417
command.Parameters.Add(param);
397418
}
@@ -478,7 +499,7 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
478499

479500
var param = command.CreateParameter();
480501
param.ParameterName = relationalParameter.InvariantName;
481-
param.Value = parameter;
502+
param.Value = parameter ?? DBNull.Value;
482503

483504
command.Parameters.Add(param);
484505
}
@@ -489,7 +510,7 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
489510
{
490511
var param = command.CreateParameter();
491512
param.ParameterName = parameter.Name;
492-
param.Value = parameter.Value;
513+
param.Value = parameter.Value ?? DBNull.Value;
493514

494515
command.Parameters.Add(param);
495516
}
@@ -566,7 +587,7 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
566587

567588
var param = command.CreateParameter();
568589
param.ParameterName = relationalParameter.InvariantName;
569-
param.Value = parameter;
590+
param.Value = parameter ?? DBNull.Value;
570591

571592
command.Parameters.Add(param);
572593
}
@@ -577,7 +598,7 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
577598
{
578599
var param = command.CreateParameter();
579600
param.ParameterName = parameter.Name;
580-
param.Value = parameter.Value;
601+
param.Value = parameter.Value ?? DBNull.Value;
581602

582603
command.Parameters.Add(param);
583604
}
@@ -589,9 +610,11 @@ public DbCommand CreateCommand(IQueryable query, IEntityType entity)
589610
#endif
590611
}
591612
#endif
592-
public string EscapeName(string name, bool isMySql)
613+
public string EscapeName(string name, bool isMySql, bool isOracle)
593614
{
594-
return isMySql ? string.Concat("`", name, "`") : string.Concat("[", name, "]");
615+
return isMySql ? string.Concat("`", name, "`") :
616+
isOracle ? string.Concat("\"", name, "\"") :
617+
string.Concat("[", name, "]");
595618
}
596619
}
597620
}

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.4.38")]
22-
[assembly: AssemblyFileVersion("1.4.38")]
21+
[assembly: AssemblyVersion("1.4.45")]
22+
[assembly: AssemblyFileVersion("1.4.45")]

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,29 @@ public object Execute(Expression expression)
100100
/// <returns>The object returned by the execution of the expression.</returns>
101101
public TResult Execute<TResult>(Expression expression)
102102
{
103-
QueryIncludeOptimizedIncludeSubPath.RemoveLazyChild(CurrentQueryable);
104-
105103
var methodCall = expression as MethodCallExpression;
106104

107105
if (methodCall == null)
108106
{
109107
throw new Exception(ExceptionMessage.GeneralException);
110108
}
111109

110+
if (methodCall.Method.Name == "All"
111+
|| methodCall.Method.Name == "Any"
112+
|| methodCall.Method.Name == "Average"
113+
|| methodCall.Method.Name == "Contains"
114+
|| methodCall.Method.Name == "Count"
115+
|| methodCall.Method.Name == "LongCount"
116+
|| methodCall.Method.Name == "Max"
117+
|| methodCall.Method.Name == "Min"
118+
|| methodCall.Method.Name == "SequenceEqual"
119+
|| methodCall.Method.Name == "Sum")
120+
{
121+
return OriginalProvider.Execute<TResult>(expression);
122+
}
123+
124+
QueryIncludeOptimizedIncludeSubPath.RemoveLazyChild(CurrentQueryable);
125+
112126
var currentQuery = CurrentQueryable;
113127
var currentMethod = methodCall.Method.GetGenericMethodDefinition();
114128

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
@@ -57,6 +57,7 @@
5757
<Compile Include="Audit\AuditConfiguration\ExcludeEntity.cs" />
5858
<Compile Include="Audit\AuditConfiguration\ExcludeProperty.cs" />
5959
<Compile Include="Audit\AuditConfiguration\Format.cs" />
60+
<Compile Include="Audit\AuditConfiguration\FormatType.cs" />
6061
<Compile Include="Audit\AuditConfiguration\FormatValue.cs" />
6162
<Compile Include="Audit\AuditConfiguration\GetEntityModifiedState.cs" />
6263
<Compile Include="Audit\AuditConfiguration\IncludeDataAnnotation.cs" />

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public AuditConfiguration()
3232
{
3333
IgnorePropertyUnchanged = true;
3434

35-
EntityValueFormatters = new List<Func<object, string, Func<object, object>>>();
35+
EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>();
3636
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>();
3737
ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>();
3838

@@ -65,7 +65,7 @@ public AuditConfiguration()
6565

6666
/// <summary>Gets or sets a list of formatter for entity values.</summary>
6767
/// <value>A list of formatter for entity values.</value>
68-
public List<Func<object, string, Func<object, object>>> EntityValueFormatters { get; set; }
68+
public List<Func<object, string, object, Func<object, object>>> EntityValueFormatters { get; set; }
6969

7070
/// <summary>Gets or sets a list of predicates to exclude or include entities.</summary>
7171
/// <value>A list of predicates to exclude or include entities.</value>
@@ -151,7 +151,7 @@ public AuditConfiguration Clone()
151151
IgnorePropertyUnchanged = IgnorePropertyUnchanged,
152152
IgnoreRelationshipAdded = IgnoreRelationshipAdded,
153153
IgnoreRelationshipDeleted = IgnoreRelationshipDeleted,
154-
EntityValueFormatters = new List<Func<object, string, Func<object, object>>>(EntityValueFormatters),
154+
EntityValueFormatters = new List<Func<object, string, object, Func<object, object>>>(EntityValueFormatters),
155155
ExcludeIncludeEntityPredicates = new List<Func<object, bool?>>(ExcludeIncludeEntityPredicates),
156156
ExcludeIncludePropertyPredicates = new List<Func<object, string, bool?>>(ExcludeIncludePropertyPredicates),
157157
SoftAddedPredicates = new List<Func<object, bool>>(SoftAddedPredicates),

src/Z.EntityFramework.Plus.EF5/Audit/AuditConfiguration/Format.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public AuditConfiguration Format<T>(Expression<Func<T, object>> propertySelector
2727

2828
foreach (var accessor in propertyNames)
2929
{
30-
EntityValueFormatters.Add((x, s) => x is T && s == accessor ? formatter : null);
30+
EntityValueFormatters.Add((x, s, v) => x is T && s == accessor ? formatter : null);
3131
}
3232

3333
return this;

0 commit comments

Comments
 (0)