Skip to content

Commit a714091

Browse files
Add fix
Add fix
1 parent f151e37 commit a714091

File tree

5 files changed

+44
-19
lines changed

5 files changed

+44
-19
lines changed

src/shared/Z.EF.Plus.BatchDelete.Shared/BatchDelete.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,16 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
434434

435435
if (isMySql)
436436
{
437-
tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" || store.Table.StartsWith(store.Schema + ".")?
438-
string.Concat("`", store.Table, "`") :
439-
string.Concat("`", store.Schema, ".", store.Table, "`");
437+
if (BatchDeleteManager.UseMySqlSchema)
438+
{
439+
tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" || store.Table.StartsWith(store.Schema + ".") ?
440+
string.Concat("`", store.Table, "`") :
441+
string.Concat("`", store.Schema, ".", store.Table, "`");
442+
}
443+
else
444+
{
445+
tableName = string.Concat("`", store.Table, "`");
446+
}
440447
}
441448
else if (isSqlCe)
442449
{

src/shared/Z.EF.Plus.BatchDelete.Shared/BatchDeleteManager.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class BatchDeleteManager
2121
/// <value>The batch delete builder to change default configuration.</value>
2222
public static Action<BatchDelete> BatchDeleteBuilder { get; set; }
2323

24+
/// <summary>Gets or sets a value indicating whether this object use schema for MySQL provider.</summary>
25+
/// <value>True if use schema for MySQL provider, false if not.</value>
26+
public static bool UseMySqlSchema { get; set; } = true;
2427
#if EFCORE
2528

2629
/// <summary>Gets or sets the factory to create an InMemory DbContext.</summary>
@@ -78,11 +81,11 @@ internal static void EnsureContextSimilar(DbContext originalContext, DbContext n
7881
}
7982

8083
#else
81-
/// <summary>
82-
/// Gets or sets a value indicating whether this object is in memory query.
83-
/// </summary>
84-
/// <value>True if this object is in memory query, false if not.</value>
85-
public static bool IsInMemoryQuery { get; set; }
84+
/// <summary>
85+
/// Gets or sets a value indicating whether this object is in memory query.
86+
/// </summary>
87+
/// <value>True if this object is in memory query, false if not.</value>
88+
public static bool IsInMemoryQuery { get; set; }
8689
#endif
8790
}
8891
}

src/shared/Z.EF.Plus.BatchUpdate.Shared/BatchUpdate.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,16 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
453453

454454
if (isMySql)
455455
{
456-
tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" || store.Table.StartsWith(store.Schema + ".") ?
457-
string.Concat("`", store.Table, "`") :
458-
string.Concat("`", store.Schema, ".", store.Table, "`");
456+
if (BatchUpdateManager.UseMySqlSchema)
457+
{
458+
tableName = string.IsNullOrEmpty(store.Schema) || store.Schema == "dbo" || store.Table.StartsWith(store.Schema + ".") ?
459+
string.Concat("`", store.Table, "`") :
460+
string.Concat("`", store.Schema, ".", store.Table, "`");
461+
}
462+
else
463+
{
464+
tableName = string.Concat("`", store.Table, "`");
465+
}
459466
}
460467
else if (isSqlCe)
461468
{
@@ -1407,8 +1414,13 @@ public List<Tuple<string, object>> GetInnerValues<T>(IQueryable<T> query, Expres
14071414

14081415
valueSql = valueSql.Trim();
14091416

1410-
// Add the destination name
1411-
valueSql = valueSql.Replace("[x]", "B");
1417+
if (updateFactory.Parameters != null && updateFactory.Parameters.Count == 1)
1418+
{
1419+
valueSql = valueSql.Replace("[" +updateFactory.Parameters.First().Name +"]", "B");
1420+
}
1421+
1422+
// Add the destination name
1423+
valueSql = valueSql.Replace("[x]", "B");
14121424
valueSql = valueSql.Replace("[c]", "B");
14131425

14141426
if (valueSql.Length > 0

src/shared/Z.EF.Plus.BatchUpdate.Shared/BatchUpdateManager.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class BatchUpdateManager
2020
/// <value>The batch update builder to change default configuration.</value>
2121
public static Action<BatchUpdate> BatchUpdateBuilder { get; set; }
2222

23+
/// <summary>Gets or sets a value indicating whether this object use schema for MySQL provider.</summary>
24+
/// <value>True if use schema for MySQL provider, false if not.</value>
25+
public static bool UseMySqlSchema { get; set; } = true;
2326
#if EFCORE
2427

2528
/// <summary>Gets or sets the factory to create an InMemory DbContext.</summary>
@@ -77,11 +80,11 @@ internal static void EnsureContextSimilar(DbContext originalContext, DbContext n
7780
}
7881

7982
#else
80-
/// <summary>
81-
/// Gets or sets a value indicating whether this object is in memory query.
82-
/// </summary>
83-
/// <value>True if this object is in memory query, false if not.</value>
84-
public static bool IsInMemoryQuery { get; set; }
83+
/// <summary>
84+
/// Gets or sets a value indicating whether this object is in memory query.
85+
/// </summary>
86+
/// <value>True if this object is in memory query, false if not.</value>
87+
public static bool IsInMemoryQuery { get; set; }
8588
#endif
8689
}
8790
}

src/shared/Z.EF.Plus.BatchUpdate.Shared/Extensions/Update.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static partial class BatchUpdateExtensions
2323
/// <returns>The number of rows affected.</returns>
2424
public static int Update<T>(this IQueryable<T> query, Expression<Func<T, T>> updateFactory) where T : class
2525
{
26-
return query.Update(updateFactory, null);
26+
return query.Update(updateFactory, null);
2727
}
2828

2929
/// <summary>

0 commit comments

Comments
 (0)