mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-31 15:56:25 +08:00
Update core
This commit is contained in:
parent
eef18eab13
commit
bb925e5029
@ -261,6 +261,27 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Core
|
||||
public virtual int ExecuteCommandWithGo(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sql))
|
||||
return 0;
|
||||
if (!sql.ToLower().Contains("go"))
|
||||
{
|
||||
return ExecuteCommand(sql);
|
||||
}
|
||||
System.Collections.ArrayList al = new System.Collections.ArrayList();
|
||||
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"^(\s*)go(\s*)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.ExplicitCapture);
|
||||
al.AddRange(reg.Split(sql));
|
||||
int count = 0;
|
||||
foreach (string item in al)
|
||||
{
|
||||
if (item.HasValue())
|
||||
{
|
||||
count += ExecuteCommand(item, parameters);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
public virtual int ExecuteCommand(string sql, params SugarParameter[] parameters)
|
||||
{
|
||||
try
|
||||
|
@ -73,7 +73,15 @@ namespace SqlSugar
|
||||
{
|
||||
foreach (var item in entityTypes)
|
||||
{
|
||||
InitTables(item);
|
||||
try
|
||||
{
|
||||
InitTables(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw new Exception(item.Name +" 创建失败,请认真检查 1、属性需要get set 2、特殊类型需要加Ignore 具体错误内容: "+ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -339,7 +347,10 @@ namespace SqlSugar
|
||||
{
|
||||
name = name.TrimStart('U');
|
||||
}
|
||||
|
||||
if (name == "char")
|
||||
{
|
||||
name = "string";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,8 @@ namespace SqlSugar
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
var columnName = string.Join(",", columnNames);
|
||||
string sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(columnNames.First()), this.SqlBuilder.GetNoTranslationColumnName(columnNames.First())), columnName);
|
||||
var pkName = string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName), columnName.Replace(",","_"));
|
||||
string sql = string.Format(this.AddPrimaryKeySql, tableName,pkName, columnName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
|
@ -228,7 +228,10 @@ namespace SqlSugar
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public MySqlBlueCopy<T> UseMySql()
|
||||
{
|
||||
return new MySqlBlueCopy<T>(this.Context, this.SqlBuilder, InsertObjs);
|
||||
}
|
||||
public SqlServerBlueCopy UseSqlServer()
|
||||
{
|
||||
PreToSql();
|
||||
@ -478,7 +481,8 @@ namespace SqlSugar
|
||||
}
|
||||
if (column.IsJson&& columnInfo.Value!=null)
|
||||
{
|
||||
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
|
||||
if(columnInfo.Value!=null)
|
||||
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
|
||||
}
|
||||
var tranColumn=EntityInfo.Columns.FirstOrDefault(it => it.IsTranscoding && it.DbColumnName.Equals(column.DbColumnName, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (tranColumn!=null&&columnInfo.Value.HasValue()) {
|
||||
|
@ -116,6 +116,11 @@ namespace SqlSugar
|
||||
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, TObject>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
||||
{
|
||||
Check.Exception(mapperObject.ReturnType.Name == "IList`1", "Mapper no support IList , Use List<T>");
|
||||
if (CallContext.MapperExpression.Value == null)
|
||||
{
|
||||
CallContext.MapperExpression.Value = new List<MapperExpression>();
|
||||
}
|
||||
CallContext.MapperExpression.Value.Add(new MapperExpression() { SqlBuilder = SqlBuilder, QueryBuilder = this.QueryBuilder, Type = MapperExpressionType.oneToOne, FillExpression = mapperObject, MappingField1Expression = mainField, MappingField2Expression=childField, Context = this.Context });
|
||||
return _Mapper<TObject>(mapperObject, mainField, childField);
|
||||
}
|
||||
public ISugarQueryable<T> Mapper<TObject>(Expression<Func<T, List<TObject>>> mapperObject, Expression<Func<T, object>> mainField, Expression<Func<T, object>> childField)
|
||||
@ -1078,7 +1083,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<List<T>> ToPageListAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToPageListAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<string> ToJsonAsync()
|
||||
@ -1103,7 +1110,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToJsonPageAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<DataTable> ToDataTableAsync()
|
||||
@ -1130,7 +1139,9 @@ namespace SqlSugar
|
||||
}
|
||||
public async Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
var oldMapping = this.Context.MappingTables;
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
this.Context.MappingTables = oldMapping;
|
||||
return await this.Clone().ToDataTablePageAsync(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,18 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISaveable<T> RemoveDataCache()
|
||||
{
|
||||
if (this.insertable != null)
|
||||
{
|
||||
this.insertable.RemoveDataCache();
|
||||
}
|
||||
if (this.updateable != null)
|
||||
{
|
||||
this.updateable.RemoveDataCache();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public ISaveable<T> InsertIgnoreColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
LoadInsertable();
|
||||
|
@ -486,6 +486,10 @@ namespace SqlSugar
|
||||
{
|
||||
var result = Builder.GetTranslationTableName(EntityName);
|
||||
result += UtilConstants.Space;
|
||||
if (result.Contains("MergeTable") && result.Trim().EndsWith(" MergeTable"))
|
||||
{
|
||||
TableShortName = null;
|
||||
}
|
||||
if (this.TableShortName.HasValue())
|
||||
{
|
||||
result += (TableShortName + UtilConstants.Space);
|
||||
|
@ -779,12 +779,6 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Entity Maintenance
|
||||
[Obsolete("Use SqlSugarClient.EntityMaintenance")]
|
||||
public virtual EntityMaintenance EntityProvider
|
||||
{
|
||||
get { return this.Context.EntityMaintenance; }
|
||||
set { this.Context.EntityMaintenance = value; }
|
||||
}
|
||||
public virtual EntityMaintenance EntityMaintenance
|
||||
{
|
||||
get
|
||||
@ -831,12 +825,12 @@ namespace SqlSugar
|
||||
{
|
||||
return new SimpleClient<T>(this);
|
||||
}
|
||||
public virtual SimpleClient GetSimpleClient()
|
||||
{
|
||||
if (this._SimpleClient == null)
|
||||
this._SimpleClient = new SimpleClient(this);
|
||||
return this._SimpleClient;
|
||||
}
|
||||
//public virtual SimpleClient GetSimpleClient()
|
||||
//{
|
||||
// if (this._SimpleClient == null)
|
||||
// this._SimpleClient = new SimpleClient(this);
|
||||
// return this._SimpleClient;
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region Dispose OR Close
|
||||
|
@ -493,7 +493,8 @@ namespace SqlSugar
|
||||
if (column.IsJson)
|
||||
{
|
||||
columnInfo.IsJson = true;
|
||||
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
|
||||
if (columnInfo.Value != null)
|
||||
columnInfo.Value = this.Context.Utilities.SerializeObject(columnInfo.Value);
|
||||
}
|
||||
if (column.IsArray)
|
||||
{
|
||||
@ -745,7 +746,7 @@ namespace SqlSugar
|
||||
DiffLogColumnInfo addItem = new DiffLogColumnInfo();
|
||||
addItem.Value = row[col.ColumnName];
|
||||
addItem.ColumnName = col.ColumnName;
|
||||
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it=>it.DbColumnName!=null).First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
|
||||
addItem.ColumnDescription = this.EntityInfo.Columns.Where(it => it.DbColumnName != null).First(it => it.DbColumnName.Equals(col.ColumnName, StringComparison.CurrentCultureIgnoreCase)).ColumnDescription;
|
||||
item.Columns.Add(addItem);
|
||||
}
|
||||
result.Add(item);
|
||||
|
@ -26,9 +26,9 @@ namespace SqlSugar
|
||||
/// </summary>
|
||||
public bool IsAutoCloseConnection { get; set; }
|
||||
/// <summary>
|
||||
/// Default SystemTable,If you do not have system table permissions, use attribute
|
||||
/// Default Attribute
|
||||
/// </summary>
|
||||
public InitKeyType InitKeyType = InitKeyType.SystemTable;
|
||||
public InitKeyType InitKeyType = InitKeyType.Attribute;
|
||||
/// <summary>
|
||||
///If true, there is only one connection instance in the same thread within the same connection string
|
||||
/// </summary>
|
||||
|
@ -120,7 +120,7 @@ namespace SqlSugar
|
||||
public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static int AggregateDistinctCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult MappingColumn<TResult>(TResult oldColumnName,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
public static TResult MappingColumn<TResult>(TResult type,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
/// <summary>
|
||||
///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.*
|
||||
/// </summary>
|
||||
|
@ -133,20 +133,8 @@ namespace SqlSugar
|
||||
if (parameter.BaseExpression is BinaryExpression || parameter.BaseExpression == null)
|
||||
{
|
||||
var oppoSiteExpression = isLeft == true ? parameter.BaseParameter.RightExpression : parameter.BaseParameter.LeftExpression;
|
||||
if (parameter.CurrentExpression is MethodCallExpression || parameter.CurrentExpression is ConditionalExpression || parameter.CurrentExpression.NodeType == ExpressionType.Coalesce)
|
||||
{
|
||||
var appendValue = value;
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Append(appendValue);
|
||||
}
|
||||
this.AppendOpreator(parameter, isLeft);
|
||||
}
|
||||
else if (value is MapperSql)
|
||||
|
||||
if (value is MapperSql)
|
||||
{
|
||||
var sql = ((MapperSql)value).Sql;
|
||||
if (isLeft == true)
|
||||
@ -162,6 +150,19 @@ namespace SqlSugar
|
||||
this.Context.Result.Append(sql);
|
||||
}
|
||||
}
|
||||
else if(parameter.CurrentExpression is MethodCallExpression || parameter.CurrentExpression is ConditionalExpression || parameter.CurrentExpression.NodeType == ExpressionType.Coalesce)
|
||||
{
|
||||
var appendValue = value;
|
||||
if (this.Context.Result.Contains(ExpressionConst.FormatSymbol))
|
||||
{
|
||||
this.Context.Result.Replace(ExpressionConst.FormatSymbol, appendValue.ObjToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.Result.Append(appendValue);
|
||||
}
|
||||
this.AppendOpreator(parameter, isLeft);
|
||||
}
|
||||
else if (oppoSiteExpression is MemberExpression)
|
||||
{
|
||||
string appendValue = Context.SqlParameterKeyWord
|
||||
|
@ -54,7 +54,7 @@ namespace SqlSugar
|
||||
|
||||
if (isExMapper)
|
||||
{
|
||||
ExtMapper();
|
||||
ExtMapper(fillInfo, mappingFild1Info, mappingFild1Info2, SelectInfo);
|
||||
}
|
||||
else if (isSameProperty)
|
||||
{
|
||||
@ -189,9 +189,15 @@ namespace SqlSugar
|
||||
return "";
|
||||
}
|
||||
|
||||
private void ExtMapper()
|
||||
private void ExtMapper(MapperExpressionInfo fillInfo, MapperExpressionInfo mappingFild1Info, MapperExpressionInfo mappingFild1Info2, MapperExpressionInfo selectInfo)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var tableName = sqlBuilder.GetTranslationTableName(fillInfo.EntityInfo.DbTableName);
|
||||
var whereLeft = sqlBuilder.GetTranslationColumnName(mappingFild1Info2.FieldName);
|
||||
var whereRight = sqlBuilder.GetTranslationColumnName(mappingFild1Info.FieldString);
|
||||
this.sql = this.context.Queryable<object>()
|
||||
.AS(tableName)
|
||||
.Where(string.Format(" {0}={1} ", whereLeft, whereRight))
|
||||
.Select(sqlBuilder.GetTranslationColumnName(selectInfo.FieldName)).ToSql().Key;
|
||||
}
|
||||
|
||||
public MapperSql GetSql()
|
||||
|
@ -245,6 +245,10 @@ namespace SqlSugar
|
||||
var value = ExpressionTool.GetMemberValue(expression.Member, expression);
|
||||
if (isSetTempData)
|
||||
{
|
||||
if (value is MapperSql)
|
||||
{
|
||||
value = (value as MapperSql).Sql;
|
||||
}
|
||||
baseParameter.CommonTempData = value;
|
||||
}
|
||||
else
|
||||
|
@ -652,7 +652,7 @@ namespace SqlSugar
|
||||
case "MappingColumn":
|
||||
var mappingColumnResult = this.Context.DbMehtods.MappingColumn(model);
|
||||
var isValid = model.Args[0].IsMember && model.Args[1].IsMember == false;
|
||||
Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
|
||||
//Check.Exception(!isValid, "SqlFunc.MappingColumn parameters error, The property name on the left, string value on the right");
|
||||
this.Context.Parameters.RemoveAll(it => it.ParameterName == model.Args[1].MemberName.ObjToString());
|
||||
return mappingColumnResult;
|
||||
case "IsNull":
|
||||
|
@ -70,6 +70,7 @@ namespace SqlSugar
|
||||
Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<object> GetScalarAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
int ExecuteCommandWithGo(string sql, params SugarParameter[] parameters);
|
||||
int ExecuteCommand(string sql, object parameters);
|
||||
int ExecuteCommand(string sql, params SugarParameter[] parameters);
|
||||
int ExecuteCommand(string sql, List<SugarParameter> parameters);
|
||||
|
@ -22,5 +22,6 @@ namespace SqlSugar
|
||||
ISaveable<T> UpdateIgnoreColumns(Expression<Func<T, object>> columns);
|
||||
ISaveable<T> UpdateWhereColumns(Expression<Func<T, object>> columns);
|
||||
ISaveable<T> EnableDiffLogEvent(object businessData = null);
|
||||
ISaveable<T> RemoveDataCache();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public interface ISimpleClient<T> where T : class, new()
|
||||
{
|
||||
SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new();
|
||||
IDeleteable<T> AsDeleteable();
|
||||
IInsertable<T> AsInsertable(List<T> insertObjs);
|
||||
IInsertable<T> AsInsertable(T insertObj);
|
||||
|
@ -160,14 +160,5 @@ namespace SqlSugar
|
||||
IUpdateable<T> Updateable<T>(T UpdateObj) where T : class, new();
|
||||
IUpdateable<T> Updateable<T>(T[] UpdateObjs) where T : class, new();
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("use Utilities")]
|
||||
IContextMethods RewritableMethods { get; set; }
|
||||
[Obsolete("use GetSimpleClient()")]
|
||||
SimpleClient SimpleClient { get; }
|
||||
[Obsolete("use EntityMaintenance")]
|
||||
EntityMaintenance EntityProvider { get; set; }
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -11,13 +11,15 @@ namespace SqlSugar
|
||||
void BeginTran();
|
||||
void CommitTran();
|
||||
void RollbackTran();
|
||||
void ChangeDatabase(string configId);
|
||||
void ChangeDatabase(dynamic configId);
|
||||
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
|
||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
void AddConnection(ConnectionConfig connection);
|
||||
SqlSugarProvider GetConnection(dynamic configId);
|
||||
|
||||
void Close();
|
||||
void Open();
|
||||
|
@ -36,6 +36,7 @@ namespace SqlSugar
|
||||
IInsertable<T> RemoveDataCache();
|
||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||
SqlServerBlueCopy UseSqlServer();
|
||||
MySqlBlueCopy<T> UseMySql();
|
||||
void AddQueue();
|
||||
|
||||
#region Obsolete
|
||||
|
@ -61,7 +61,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE DATABASE {0}";
|
||||
return "CREATE DATABASE {0} CHARACTER SET utf8 COLLATE utf8_general_ci ";
|
||||
}
|
||||
}
|
||||
protected override string AddPrimaryKeySql
|
||||
|
@ -0,0 +1,140 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class MySqlBlueCopy<T>
|
||||
{
|
||||
internal SqlSugarProvider Context { get; set; }
|
||||
internal ISqlBuilder Builder { get; set; }
|
||||
internal T[] Entitys { get; set; }
|
||||
private MySqlBlueCopy()
|
||||
{
|
||||
|
||||
}
|
||||
public MySqlBlueCopy(SqlSugarProvider context, ISqlBuilder builder, T []entitys)
|
||||
{
|
||||
this.Context = context;
|
||||
this.Builder = builder;
|
||||
this.Entitys = entitys;
|
||||
}
|
||||
|
||||
public bool ExecuteBlueCopy()
|
||||
{
|
||||
var IsBulkLoad = false;
|
||||
if (Entitys == null || Entitys.Length <= 0)
|
||||
return IsBulkLoad;
|
||||
DataTable dt = new DataTable();
|
||||
Type type = typeof(T);
|
||||
var entity = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
dt.TableName = this.Builder.GetTranslationColumnName(entity.DbTableName);
|
||||
//创建属性的集合
|
||||
List<PropertyInfo> pList = new List<PropertyInfo>();
|
||||
//把所有的public属性加入到集合 并添加DataTable的列
|
||||
Array.ForEach(entity.Columns.ToArray(), p => {
|
||||
if (!p.IsIgnore&& !p.IsOnlyIgnoreInsert)
|
||||
{
|
||||
pList.Add(p.PropertyInfo); dt.Columns.Add(p.PropertyName);
|
||||
}
|
||||
});
|
||||
DataRow row = null;
|
||||
foreach (T item in Entitys)
|
||||
{
|
||||
row = dt.NewRow();
|
||||
pList.ForEach(p =>
|
||||
{
|
||||
var name = p.Name;
|
||||
if (entity.Columns.Any(it => it.PropertyName == name))
|
||||
{
|
||||
name=entity.Columns.First(it => it.PropertyName == name).DbColumnName;
|
||||
}
|
||||
row[name] = p.GetValue(item, null);
|
||||
});
|
||||
dt.Rows.Add(row);
|
||||
}
|
||||
var dllPath = AppDomain.CurrentDomain.BaseDirectory + "failFiles";
|
||||
DirectoryInfo dir = new DirectoryInfo(dllPath);
|
||||
if (!dir.Exists)
|
||||
{
|
||||
dir.Create();
|
||||
}
|
||||
var fileName = dllPath + "\\" + Guid.NewGuid().ToString() + ".csv";
|
||||
var dataTableToCsv = DataTableToCsvString(dt);
|
||||
File.WriteAllText(fileName, dataTableToCsv, Encoding.UTF8);
|
||||
MySqlConnection conn = this.Context.Ado.Connection as MySqlConnection;
|
||||
try
|
||||
{
|
||||
this.Context.Ado.Open();
|
||||
// IsolationLevel.Parse
|
||||
MySqlBulkLoader bulk = new MySqlBulkLoader(conn)
|
||||
{
|
||||
CharacterSet = "UTF8",
|
||||
FieldTerminator = ",",
|
||||
FieldQuotationCharacter = '"',
|
||||
EscapeCharacter = '"',
|
||||
LineTerminator = "\r\n",
|
||||
FileName = fileName,
|
||||
NumberOfLinesToSkip = 0,
|
||||
TableName = dt.TableName,
|
||||
Local = true,
|
||||
};
|
||||
bulk.Columns.AddRange(dt.Columns.Cast<DataColumn>().Select(colum => colum.ColumnName).Distinct().ToArray());
|
||||
IsBulkLoad = bulk.Load() > 0;
|
||||
//执行成功才删除文件
|
||||
if (IsBulkLoad && File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.Context.Ado.Close();
|
||||
}
|
||||
return IsBulkLoad; ;
|
||||
}
|
||||
|
||||
public Task<bool> ExecuteBlueCopyAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteBlueCopy());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///DataTable to CSV
|
||||
/// </summary>
|
||||
/// <param name="table">datatable</param>
|
||||
/// <returns>CSV</returns>
|
||||
public string DataTableToCsvString(DataTable table)
|
||||
{
|
||||
if (table.Rows.Count == 0)
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
DataColumn colum;
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
for (int i = 0; i < table.Columns.Count; i++)
|
||||
{
|
||||
colum = table.Columns[i];
|
||||
if (i != 0) sb.Append(",");
|
||||
if (colum.DataType == typeof(string) && row[colum].ToString().Contains(","))
|
||||
{
|
||||
sb.Append("\"" + row[colum].ToString().Replace("\"", "\"\"") + "\"");
|
||||
}
|
||||
else sb.Append(row[colum].ToString());
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -191,13 +191,13 @@ namespace SqlSugar
|
||||
public override string ToInt32(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
|
||||
return string.Format(" CAST({0} AS INT4)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public override string ToInt64(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
|
||||
return string.Format(" CAST({0} AS INT8)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public override string ToString(MethodCallExpressionModel model)
|
||||
@ -221,7 +221,7 @@ namespace SqlSugar
|
||||
public override string ToBool(MethodCallExpressionModel model)
|
||||
{
|
||||
var parameter = model.Args[0];
|
||||
return string.Format(" CAST({0} AS SIGNED)", parameter.MemberName);
|
||||
return string.Format(" CAST({0} AS boolean)", parameter.MemberName);
|
||||
}
|
||||
|
||||
public override string ToDecimal(MethodCallExpressionModel model)
|
||||
|
@ -234,9 +234,21 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateIndexSql => throw new NotSupportedException();
|
||||
protected override string CreateIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE {3} INDEX Index_{0}_{2} ON {0}({1})";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyIndexSql => throw new NotSupportedException();
|
||||
protected override string IsAnyIndexSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT count(*) FROM sqlite_master WHERE name = '{0}'";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddDefaultValueSql => throw new NotSupportedException();
|
||||
#endregion
|
||||
|
@ -30,7 +30,10 @@ namespace SqlSugar
|
||||
{
|
||||
this.Context = context;
|
||||
}
|
||||
|
||||
public SimpleClient<ChangeType> Change<ChangeType>() where ChangeType : class, new()
|
||||
{
|
||||
return this.Context.GetSimpleClient<ChangeType>();
|
||||
}
|
||||
public ISugarQueryable<T> AsQueryable()
|
||||
{
|
||||
return Context.Queryable<T>();
|
||||
@ -189,31 +192,31 @@ namespace SqlSugar
|
||||
{
|
||||
return Context.Queryable<T>().SingleAsync(whereExpression);
|
||||
}
|
||||
public async virtual Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result = await Context.Queryable<T>().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result =await Context.Queryable<T>().Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
public virtual async Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result =await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(whereExpression).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page)
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result = Context.Queryable<T>().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result =await Context.Queryable<T>().Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
public virtual Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
public virtual async Task<List<T>> GetPageListAsync(List<IConditionalModel> conditionalList, PageModel page, Expression<Func<T, object>> orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
|
||||
{
|
||||
RefAsync<int> count = 0;
|
||||
var result = Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
var result =await Context.Queryable<T>().OrderByIF(orderByExpression != null, orderByExpression, orderByType).Where(conditionalList).ToPageListAsync(page.PageIndex, page.PageSize, count);
|
||||
page.PageCount = count;
|
||||
return result;
|
||||
}
|
||||
|
@ -543,7 +543,44 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region TenantManager
|
||||
public void ChangeDatabase(string configId)
|
||||
public void AddConnection(ConnectionConfig connection)
|
||||
{
|
||||
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");
|
||||
InitTenant();
|
||||
var db = this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId == connection.ConfigId);
|
||||
if (db == null)
|
||||
{
|
||||
if (this._AllClients == null)
|
||||
{
|
||||
this._AllClients = new List<SugarTenant>();
|
||||
}
|
||||
var provider = new SqlSugarProvider(connection);
|
||||
if (connection.AopEvents != null)
|
||||
{
|
||||
provider.Ado.IsEnableLogEvent = true;
|
||||
}
|
||||
this._AllClients.Add(new SugarTenant()
|
||||
{
|
||||
ConnectionConfig = connection,
|
||||
Context = provider
|
||||
});
|
||||
}
|
||||
}
|
||||
public SqlSugarProvider GetConnection(dynamic configId)
|
||||
{
|
||||
InitTenant();
|
||||
var db = this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId == configId);
|
||||
if (db == null)
|
||||
{
|
||||
Check.Exception(true, "ConfigId was not found {0}", configId);
|
||||
}
|
||||
if (db.Context == null)
|
||||
{
|
||||
db.Context = new SqlSugarProvider(db.ConnectionConfig);
|
||||
}
|
||||
return db.Context;
|
||||
}
|
||||
public void ChangeDatabase(dynamic configId)
|
||||
{
|
||||
var isLog = _Context.Ado.IsEnableLogEvent;
|
||||
Check.Exception(!_AllClients.Any(it => it.ConnectionConfig.ConfigId == configId), "ConfigId was not found {0}", configId);
|
||||
@ -573,7 +610,7 @@ namespace SqlSugar
|
||||
public void BeginTran()
|
||||
{
|
||||
_IsAllTran = true;
|
||||
this.Context.Ado.BeginTran();
|
||||
AllClientEach(it => it.Ado.BeginTran());
|
||||
}
|
||||
public void CommitTran()
|
||||
{
|
||||
@ -749,6 +786,18 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
private void InitTenant()
|
||||
{
|
||||
if (this._AllClients == null)
|
||||
{
|
||||
this._AllClients = new List<SugarTenant>();
|
||||
this._AllClients.Add(new SugarTenant()
|
||||
{
|
||||
ConnectionConfig = this.CurrentConnectionConfig,
|
||||
Context = this.Context
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private SqlSugarProvider Synchronization()
|
||||
{
|
||||
@ -910,20 +959,5 @@ namespace SqlSugar
|
||||
this.CurrentConnectionConfig = Tenant.ConnectionConfig;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use GetSimpleClient<T>")]
|
||||
public SimpleClient GetSimpleClient()
|
||||
{
|
||||
return this.Context.GetSimpleClient();
|
||||
}
|
||||
[Obsolete("Use EntityMaintenance")]
|
||||
public EntityMaintenance EntityProvider { get { return this.Context.EntityProvider; } set { this.Context.EntityProvider = value; } }
|
||||
[Obsolete("Use Utilities")]
|
||||
public IContextMethods RewritableMethods { get { return this.Context.RewritableMethods; } set { this.Context.RewritableMethods = value; } }
|
||||
[Obsolete("Use GetSimpleClient")]
|
||||
public SimpleClient SimpleClient { get { return this.Context.SimpleClient; } }
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ namespace SqlSugar
|
||||
for (int i = 0; i < st.FrameCount; i++)
|
||||
{
|
||||
var frame = st.GetFrame(i);
|
||||
if (frame.GetMethod().Module.Name.ToLower() != "sqlsugar.dll" && frame.GetMethod().Name.First() != '<')
|
||||
if (frame.GetMethod().Module.Name.ToLower() != "sqlsugar.dll"&& frame.GetMethod().Name.First()!='<')
|
||||
{
|
||||
info.MyStackTraceList.Add(new StackTraceInfoItem()
|
||||
{
|
||||
@ -93,8 +93,8 @@ namespace SqlSugar
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName + ",", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName, RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0}\+", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0} ", "\\" + itemParameter.ParameterName), "+" + newName + " ", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName), " " + newName + "+", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\+{0} ", "\\" + itemParameter.ParameterName), "+" + newName +" ", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@" {0}\+", "\\" + itemParameter.ParameterName)," "+ newName + "+", RegexOptions.IgnoreCase);
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"\|\|{0}\|\|", "\\" + itemParameter.ParameterName), "+" + newName + "+", RegexOptions.IgnoreCase);
|
||||
return itemSql;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user