mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Synchronization code
This commit is contained in:
parent
b3b98cfd11
commit
3e30501e1d
@ -89,6 +89,20 @@ namespace SqlSugar
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IStorageable<T> DefaultAddElseUpdate()
|
||||||
|
{
|
||||||
|
var column = this.Context.EntityMaintenance.GetEntityInfo<T>().Columns.FirstOrDefault(it=>it.IsPrimarykey);
|
||||||
|
if (column == null) Check.ExceptionEasy("DefaultAddElseUpdate() need primary key", "DefaultAddElseUpdate()这个方法只能用于主键");
|
||||||
|
return this.SplitUpdate(it =>
|
||||||
|
{
|
||||||
|
var itemPkValue = column.PropertyInfo.GetValue(it.Item);
|
||||||
|
var defaultValue =UtilMethods.GetDefaultValue(column.PropertyInfo.PropertyType);
|
||||||
|
var result= itemPkValue != null && itemPkValue.ObjToString() != defaultValue.ObjToString();
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}).SplitInsert(it => true);
|
||||||
|
}
|
||||||
|
|
||||||
public int ExecuteCommand()
|
public int ExecuteCommand()
|
||||||
{
|
{
|
||||||
var result = 0;
|
var result = 0;
|
||||||
@ -107,6 +121,16 @@ namespace SqlSugar
|
|||||||
result +=await x.AsUpdateable.ExecuteCommandAsync();
|
result +=await x.AsUpdateable.ExecuteCommandAsync();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public int ExecuteSqlBulkCopy()
|
||||||
|
{
|
||||||
|
var storage = this.ToStorage();
|
||||||
|
return storage.BulkCopy() + storage.BulkUpdate();
|
||||||
|
}
|
||||||
|
public async Task<int> ExecuteSqlBulkCopyAsync()
|
||||||
|
{
|
||||||
|
var storage =await this.ToStorageAsync();
|
||||||
|
return await storage.BulkCopyAsync() + await storage.BulkUpdateAsync();
|
||||||
|
}
|
||||||
public StorageableResult<T> ToStorage()
|
public StorageableResult<T> ToStorage()
|
||||||
{
|
{
|
||||||
if (whereFuncs == null || whereFuncs.Count == 0)
|
if (whereFuncs == null || whereFuncs.Count == 0)
|
||||||
|
@ -139,6 +139,7 @@ namespace SqlSugar
|
|||||||
CheckWhere();
|
CheckWhere();
|
||||||
PreToSql();
|
PreToSql();
|
||||||
AutoRemoveDataCache();
|
AutoRemoveDataCache();
|
||||||
|
Check.ExceptionEasy(this.UpdateParameterIsNull&&this.UpdateBuilder.DbColumnInfoList.Count() == this.UpdateObjs.Length && this.UpdateObjs.Length==this.UpdateBuilder.DbColumnInfoList.Count(it => it.IsPrimarykey), "The primary key cannot be updated", "主键不能更新,更新主键会对代码逻辑存在未知隐患,如果非要更新:建议你删除在插入或者新建一个没主键的类。");
|
||||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||||
string sql = UpdateBuilder.ToSqlString();
|
string sql = UpdateBuilder.ToSqlString();
|
||||||
ValidateVersion();
|
ValidateVersion();
|
||||||
|
@ -32,4 +32,22 @@ namespace SqlSugar.DbConvert
|
|||||||
return (T)Enum.Parse(undertype, str);
|
return (T)Enum.Parse(undertype, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class CommonPropertyConvert : ISugarDataConverter
|
||||||
|
{
|
||||||
|
public SugarParameter ParameterConverter<T>(object columnValue, int columnIndex)
|
||||||
|
{
|
||||||
|
var name = "@Common" + columnIndex;
|
||||||
|
Type undertype = SqlSugar.UtilMethods.GetUnderType(typeof(T));//获取没有nullable的枚举类型
|
||||||
|
return new SugarParameter(name, columnValue, undertype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T QueryConverter<T>(IDataRecord dr, int i)
|
||||||
|
{
|
||||||
|
|
||||||
|
var value = dr.GetValue(i);
|
||||||
|
return (T)UtilMethods.ChangeType2(value, typeof(T));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,9 @@ namespace SqlSugar
|
|||||||
IStorageable<T> As(string tableName);
|
IStorageable<T> As(string tableName);
|
||||||
int ExecuteCommand();
|
int ExecuteCommand();
|
||||||
Task<int> ExecuteCommandAsync();
|
Task<int> ExecuteCommandAsync();
|
||||||
|
int ExecuteSqlBulkCopy();
|
||||||
|
Task<int> ExecuteSqlBulkCopyAsync();
|
||||||
|
IStorageable<T> DefaultAddElseUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StorageableInfo<T> where T : class, new()
|
public class StorageableInfo<T> where T : class, new()
|
||||||
|
@ -203,6 +203,7 @@ namespace SqlSugar
|
|||||||
{ typeof(bool[]),NpgsqlDbType.Boolean},
|
{ typeof(bool[]),NpgsqlDbType.Boolean},
|
||||||
{typeof(DateTime[]),NpgsqlDbType.Date},
|
{typeof(DateTime[]),NpgsqlDbType.Date},
|
||||||
{typeof(float[]),NpgsqlDbType.Real},
|
{typeof(float[]),NpgsqlDbType.Real},
|
||||||
|
{typeof(Guid[]),NpgsqlDbType.Uuid},
|
||||||
|
|
||||||
|
|
||||||
{ typeof(int?[]),NpgsqlDbType.Integer},
|
{ typeof(int?[]),NpgsqlDbType.Integer},
|
||||||
@ -213,6 +214,7 @@ namespace SqlSugar
|
|||||||
{ typeof(byte?[]),NpgsqlDbType.Bytea},
|
{ typeof(byte?[]),NpgsqlDbType.Bytea},
|
||||||
{ typeof(bool?[]),NpgsqlDbType.Boolean},
|
{ typeof(bool?[]),NpgsqlDbType.Boolean},
|
||||||
{typeof(DateTime?[]),NpgsqlDbType.Date},
|
{typeof(DateTime?[]),NpgsqlDbType.Date},
|
||||||
|
{typeof(Guid?[]),NpgsqlDbType.Uuid},
|
||||||
|
|
||||||
|
|
||||||
{ typeof(string[]), NpgsqlDbType.Text},
|
{ typeof(string[]), NpgsqlDbType.Text},
|
||||||
|
Loading…
Reference in New Issue
Block a user