mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 InsertDict DBNull.Value 值处理;#1336
This commit is contained in:
parent
7477e5f5ce
commit
1d06f677e4
@ -876,6 +876,7 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static InsertDictImpl InsertDict(this IFreeSql freesql, Dictionary<string, object> source)
|
public static InsertDictImpl InsertDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
{
|
{
|
||||||
|
LocalReplaceDictDBNullValue(source);
|
||||||
var insertDict = new InsertDictImpl(freesql);
|
var insertDict = new InsertDictImpl(freesql);
|
||||||
insertDict._insertProvider.AppendData(source);
|
insertDict._insertProvider.AppendData(source);
|
||||||
return insertDict;
|
return insertDict;
|
||||||
@ -887,10 +888,20 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static InsertDictImpl InsertDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
public static InsertDictImpl InsertDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
{
|
{
|
||||||
|
if (source?.Any() == true) foreach (var dict in source) LocalReplaceDictDBNullValue(dict);
|
||||||
var insertDict = new InsertDictImpl(freesql);
|
var insertDict = new InsertDictImpl(freesql);
|
||||||
insertDict._insertProvider.AppendData(source);
|
insertDict._insertProvider.AppendData(source);
|
||||||
return insertDict;
|
return insertDict;
|
||||||
}
|
}
|
||||||
|
static void LocalReplaceDictDBNullValue(Dictionary<string, object> dict)
|
||||||
|
{
|
||||||
|
if (dict == null) return;
|
||||||
|
foreach (var key in dict.Keys)
|
||||||
|
{
|
||||||
|
var val = dict[key];
|
||||||
|
if (val == DBNull.Value) dict[key] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新数据字典 Dictionary<string, object>
|
/// 更新数据字典 Dictionary<string, object>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -898,6 +909,7 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
{
|
{
|
||||||
|
LocalReplaceDictDBNullValue(source);
|
||||||
var updateDict = new UpdateDictImpl(freesql);
|
var updateDict = new UpdateDictImpl(freesql);
|
||||||
updateDict._updateProvider.SetSource(source);
|
updateDict._updateProvider.SetSource(source);
|
||||||
return updateDict;
|
return updateDict;
|
||||||
@ -909,6 +921,7 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
public static UpdateDictImpl UpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
{
|
{
|
||||||
|
if (source?.Any() == true) foreach (var dict in source) LocalReplaceDictDBNullValue(dict);
|
||||||
var updateDict = new UpdateDictImpl(freesql);
|
var updateDict = new UpdateDictImpl(freesql);
|
||||||
updateDict._updateProvider.SetSource(source);
|
updateDict._updateProvider.SetSource(source);
|
||||||
return updateDict;
|
return updateDict;
|
||||||
@ -929,12 +942,14 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
{
|
{
|
||||||
|
LocalReplaceDictDBNullValue(source);
|
||||||
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
||||||
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
||||||
return insertOrUpdateDict;
|
return insertOrUpdateDict;
|
||||||
}
|
}
|
||||||
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
public static InsertOrUpdateDictImpl InsertOrUpdateDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
{
|
{
|
||||||
|
if (source?.Any() == true) foreach (var dict in source) LocalReplaceDictDBNullValue(dict);
|
||||||
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
var insertOrUpdateDict = new InsertOrUpdateDictImpl(freesql);
|
||||||
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
insertOrUpdateDict._insertOrUpdateProvider.SetSource(source);
|
||||||
return insertOrUpdateDict;
|
return insertOrUpdateDict;
|
||||||
@ -946,6 +961,7 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, Dictionary<string, object> source)
|
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, Dictionary<string, object> source)
|
||||||
{
|
{
|
||||||
|
LocalReplaceDictDBNullValue(source);
|
||||||
var deleteDict = new DeleteDictImpl(freesql);
|
var deleteDict = new DeleteDictImpl(freesql);
|
||||||
UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(source, deleteDict._deleteProvider._orm, ref deleteDict._deleteProvider._table);
|
UpdateProvider<Dictionary<string, object>>.GetDictionaryTableInfo(source, deleteDict._deleteProvider._orm, ref deleteDict._deleteProvider._table);
|
||||||
var primarys = UpdateDictImpl.GetPrimarys(deleteDict._deleteProvider._table, source.Keys.ToArray());
|
var primarys = UpdateDictImpl.GetPrimarys(deleteDict._deleteProvider._table, source.Keys.ToArray());
|
||||||
@ -959,6 +975,7 @@ SELECT ");
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
public static DeleteDictImpl DeleteDict(this IFreeSql freesql, IEnumerable<Dictionary<string, object>> source)
|
||||||
{
|
{
|
||||||
|
if (source?.Any() == true) foreach (var dict in source) LocalReplaceDictDBNullValue(dict);
|
||||||
DeleteDictImpl deleteDict = null;
|
DeleteDictImpl deleteDict = null;
|
||||||
if (source.Select(a => string.Join(",", a.Keys)).Distinct().Count() == 1)
|
if (source.Select(a => string.Join(",", a.Keys)).Distinct().Count() == 1)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user