mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Core
This commit is contained in:
parent
0809d3154f
commit
2b2a810b9c
@ -11,6 +11,7 @@ namespace SqlSugar
|
||||
public virtual SqlSugarClient Context { get; set; }
|
||||
private bool IsBackupTable { get; set; }
|
||||
private int MaxBackupDataRows { get; set; }
|
||||
private int DefultLength { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
@ -20,6 +21,12 @@ namespace SqlSugar
|
||||
this.MaxBackupDataRows = maxBackupDataRows;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual ICodeFirst SetStringDefaultLength(int length) {
|
||||
DefultLength = length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
|
||||
@ -67,12 +74,22 @@ namespace SqlSugar
|
||||
protected virtual void Execute(Type entityType)
|
||||
{
|
||||
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(entityType);
|
||||
if (this.DefultLength > 0) {
|
||||
foreach (var item in entityInfo.Columns)
|
||||
{
|
||||
if (item.PropertyInfo.PropertyType == UtilConstants.StringType && item.DataType.IsNullOrEmpty()&& item.Length==0) {
|
||||
item.Length = DefultLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
var tableName = GetTableName(entityInfo);
|
||||
var isAny = this.Context.DbMaintenance.IsAnyTable(tableName);
|
||||
if (isAny)
|
||||
ExistLogic(entityInfo);
|
||||
else
|
||||
NoExistLogic(entityInfo);
|
||||
|
||||
this.Context.DbMaintenance.AddRemark(entityInfo);
|
||||
}
|
||||
public virtual void NoExistLogic(EntityInfo entityInfo)
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ namespace SqlSugar
|
||||
cacheKey = GetCacheKey(cacheKey);
|
||||
var sql = string.Format(this.GetColumnInfosByTableNameSql, tableName);
|
||||
if (isCache)
|
||||
return GetListOrCache<DbColumnInfo>(cacheKey, sql).GroupBy(it=>it.DbColumnName).Select(it=>it.First()).ToList();
|
||||
return GetListOrCache<DbColumnInfo>(cacheKey, sql).GroupBy(it => it.DbColumnName).Select(it => it.First()).ToList();
|
||||
else
|
||||
return this.Context.Ado.SqlQuery<DbColumnInfo>(sql).GroupBy(it => it.DbColumnName).Select(it => it.First()).ToList();
|
||||
|
||||
@ -208,6 +208,79 @@ namespace SqlSugar
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool AddColumnRemark(string columnName, string tableName, string description)
|
||||
{
|
||||
string sql = string.Format(this.AddColumnRemarkSql, columnName, tableName, description);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool DeleteColumnRemark(string columnName, string tableName)
|
||||
{
|
||||
string sql = string.Format(this.DeleteColumnRemarkSql, columnName, tableName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool IsAnyColumnRemark(string columnName, string tableName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyColumnRemarkSql, columnName, tableName);
|
||||
var dt=this.Context.Ado.GetDataTable(sql);
|
||||
return dt.Rows!=null&&dt.Rows.Count>0;
|
||||
}
|
||||
public virtual bool AddTableRemark(string tableName, string description)
|
||||
{
|
||||
string sql = string.Format(this.AddTableRemarkSql, tableName, description);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool DeleteTableRemark(string tableName)
|
||||
{
|
||||
string sql = string.Format(this.DeleteTableRemarkSql,tableName);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public virtual bool IsAnyTableRemark(string tableName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyTableRemarkSql, tableName);
|
||||
var dt=this.Context.Ado.GetDataTable(sql);
|
||||
return dt.Rows != null && dt.Rows.Count > 0;
|
||||
}
|
||||
public virtual bool AddRemark(EntityInfo entity)
|
||||
{
|
||||
var db = this.Context;
|
||||
var columns = entity.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
|
||||
foreach (var item in columns)
|
||||
{
|
||||
if (item.ColumnDescription != null)
|
||||
{
|
||||
//column remak
|
||||
if (db.DbMaintenance.IsAnyColumnRemark(item.DbColumnName, item.DbTableName))
|
||||
{
|
||||
db.DbMaintenance.DeleteColumnRemark(item.DbColumnName, item.DbTableName);
|
||||
db.DbMaintenance.AddColumnRemark(item.DbColumnName, item.DbTableName, item.ColumnDescription);
|
||||
}
|
||||
else
|
||||
{
|
||||
db.DbMaintenance.AddColumnRemark(item.DbColumnName, item.DbTableName, item.ColumnDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//table remak
|
||||
if (entity.TableDescription != null)
|
||||
{
|
||||
if (db.DbMaintenance.IsAnyTableRemark(entity.DbTableName))
|
||||
{
|
||||
db.DbMaintenance.DeleteTableRemark(entity.DbTableName);
|
||||
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription);
|
||||
}
|
||||
else
|
||||
{
|
||||
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
|
@ -43,6 +43,12 @@ namespace SqlSugar
|
||||
protected abstract string DropConstraintSql { get; }
|
||||
protected abstract string AddPrimaryKeySql { get; }
|
||||
protected abstract string RenameColumnSql { get; }
|
||||
protected abstract string AddColumnRemarkSql { get; }
|
||||
protected abstract string DeleteColumnRemarkSql { get; }
|
||||
protected abstract string IsAnyColumnRemarkSql { get; }
|
||||
protected abstract string AddTableRemarkSql { get; }
|
||||
protected abstract string DeleteTableRemarkSql { get; }
|
||||
protected abstract string IsAnyTableRemarkSql { get; }
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
|
@ -27,6 +27,10 @@ namespace SqlSugar
|
||||
{
|
||||
var sugarTable = (SugarTable)sugarAttributeInfo;
|
||||
result.DbTableName = sugarTable.TableName;
|
||||
result.TableDescription = sugarTable.TableDescription;
|
||||
}
|
||||
if (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null) {
|
||||
this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService(type,result);
|
||||
}
|
||||
result.Type = type;
|
||||
result.EntityName = result.Type.Name;
|
||||
|
@ -50,6 +50,12 @@ namespace SqlSugar
|
||||
QueryBuilder.Clear();
|
||||
}
|
||||
|
||||
public ISugarQueryable<T> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T>().WithCacheIF(IsCache, CacheTime);
|
||||
CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T> AS<T2>(string tableName)
|
||||
{
|
||||
var entityName = typeof(T2).Name;
|
||||
@ -1264,23 +1270,28 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
private ISugarQueryable<T> CopyQueryable()
|
||||
protected ISugarQueryable<T> CopyQueryable()
|
||||
{
|
||||
var asyncContext = this.Context.Utilities.CopyContext(true);
|
||||
asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
||||
var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime);
|
||||
CopyQueryBuilder(asyncQueryable.QueryBuilder); return asyncQueryable;
|
||||
}
|
||||
|
||||
var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty);
|
||||
var asyncQueryableBuilder = asyncQueryable.QueryBuilder;
|
||||
protected void CopyQueryBuilder(QueryBuilder asyncQueryableBuilder)
|
||||
{
|
||||
var pars = new List<SugarParameter>();
|
||||
pars.AddRange(this.QueryBuilder.Parameters);
|
||||
asyncQueryableBuilder.Take = this.QueryBuilder.Take;
|
||||
asyncQueryableBuilder.Skip = this.QueryBuilder.Skip;
|
||||
asyncQueryableBuilder.SelectValue = this.QueryBuilder.SelectValue;
|
||||
asyncQueryableBuilder.WhereInfos = this.QueryBuilder.WhereInfos;
|
||||
asyncQueryableBuilder.WhereInfos =this.Context.Utilities.TranslateCopy(this.QueryBuilder.WhereInfos);
|
||||
asyncQueryableBuilder.EasyJoinInfos = this.QueryBuilder.EasyJoinInfos;
|
||||
asyncQueryableBuilder.JoinQueryInfos = this.QueryBuilder.JoinQueryInfos;
|
||||
asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex;
|
||||
asyncQueryableBuilder.EntityType = this.QueryBuilder.EntityType;
|
||||
asyncQueryableBuilder.EntityName = this.QueryBuilder.EntityName;
|
||||
asyncQueryableBuilder.Parameters = this.QueryBuilder.Parameters;
|
||||
asyncQueryableBuilder.Parameters = pars;
|
||||
asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName;
|
||||
asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString;
|
||||
asyncQueryableBuilder.GroupByValue = this.QueryBuilder.GroupByValue;
|
||||
@ -1288,7 +1299,8 @@ namespace SqlSugar
|
||||
asyncQueryableBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter;
|
||||
asyncQueryableBuilder.PartitionByValue = this.QueryBuilder.PartitionByValue;
|
||||
asyncQueryableBuilder.JoinExpression = this.QueryBuilder.JoinExpression;
|
||||
return asyncQueryable;
|
||||
asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex;
|
||||
asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@ -1460,6 +1472,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T,T2> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T,T2>((t,t2)=>new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -1737,6 +1755,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2,T3> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2,T3>((t, t2,t3) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -2046,6 +2070,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2,T3,T4> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2,T3,T4>((t, t2,t3,t4) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -2358,6 +2388,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4,T5> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4,T5>((t, t2, t3, t4,t5) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -2660,6 +2696,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5,T6> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5,T6>((t, t2, t3, t4, t5,T6) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -2989,6 +3031,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6,T7> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6,T7>((t, t2, t3, t4, t5, T6,t7) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -3344,6 +3392,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7,T8> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7,T8>((t, t2, t3, t4, t5, T6, t7,t8) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -3723,6 +3777,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8,T9> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8,T9>((t, t2, t3, t4, t5, T6, t7, t8,t9) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -4126,6 +4186,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9,T10>((t, t2, t3, t4, t5, T6, t7, t8, t9,t10) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -4553,6 +4619,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>((t, t2, t3, t4, t5, T6, t7, t8, t9,t10,t11) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
@ -5006,6 +5078,12 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12> Clone()
|
||||
{
|
||||
var queryable = this.Context.Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12>((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11,t12) => new object[] { }).WithCacheIF(IsCache, CacheTime);
|
||||
base.CopyQueryBuilder(queryable.QueryBuilder);
|
||||
return queryable;
|
||||
}
|
||||
public new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> AS<AsT>(string tableName)
|
||||
{
|
||||
var entityName = typeof(AsT).Name;
|
||||
|
@ -97,8 +97,8 @@ namespace SqlSugar
|
||||
|
||||
public IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
var ignoreColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Contains(it.PropertyName)).ToList();
|
||||
var ignoreColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it).ToLower()).ToList();
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Contains(it.PropertyName.ToLower())).ToList();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -203,8 +203,33 @@ namespace SqlSugar
|
||||
this.UpdateBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList.Where(it => UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
|
||||
return this;
|
||||
}
|
||||
[Obsolete("Use IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")]
|
||||
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, object>> columns)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
UpdateColumns(columns);
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, bool>> columns)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
UpdateColumns(columns);
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Func<string, bool> updateColumMethod)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
UpdateColumns(updateColumMethod);
|
||||
return this;
|
||||
}
|
||||
public IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns, Expression<Func<T, T>> columns)
|
||||
{
|
||||
if (isUpdateColumns)
|
||||
UpdateColumns(columns);
|
||||
return this;
|
||||
}
|
||||
|
||||
[Obsolete("Use IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);")]
|
||||
public IUpdateable<T> Where(bool isUpdateNull, bool IsOffIdentity = false)
|
||||
{
|
||||
UpdateBuilder.IsOffIdentity = IsOffIdentity;
|
||||
@ -499,7 +524,7 @@ namespace SqlSugar
|
||||
}
|
||||
else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.ByteArrayType))
|
||||
{
|
||||
if (UtilMethods.GetLong((byte[])dbVersion)>UtilMethods.GetLong((byte[])currentVersion))
|
||||
if (UtilMethods.GetLong((byte[])dbVersion) > UtilMethods.GetLong((byte[])currentVersion))
|
||||
{
|
||||
throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ namespace SqlSugar
|
||||
result.IdentificationList.Add(queryBuilder.Take.ObjToString());
|
||||
result.IdentificationList.Add(queryBuilder.Skip.ObjToString());
|
||||
result.IdentificationList.Add(queryBuilder.IsCount.ObjToString());
|
||||
result.IdentificationList.Add(queryBuilder.GetSelectValue.ObjToString().Length.ObjToString());
|
||||
if (queryBuilder.Parameters.HasValue())
|
||||
{
|
||||
foreach (var item in queryBuilder.Parameters)
|
||||
|
@ -94,5 +94,6 @@ namespace SqlSugar
|
||||
|
||||
|
||||
public Action<PropertyInfo, EntityColumnInfo> EntityService{ get; set; }
|
||||
public Action<Type,EntityInfo> EntityNameService { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace SqlSugar
|
||||
private string _DbTableName;
|
||||
public string EntityName { get; set; }
|
||||
public string DbTableName { get { return _DbTableName == null ? EntityName : _DbTableName; } set { _DbTableName = value; } }
|
||||
public string TableDescription { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public List<EntityColumnInfo> Columns { get; set; }
|
||||
}
|
||||
|
@ -10,9 +10,15 @@ namespace SqlSugar
|
||||
public class SugarTable : Attribute {
|
||||
private SugarTable() { }
|
||||
public string TableName { get; set; }
|
||||
public string TableDescription { get; set; }
|
||||
public SugarTable(string tableName) {
|
||||
this.TableName = tableName;
|
||||
}
|
||||
public SugarTable(string tableName,string tableDescription)
|
||||
{
|
||||
this.TableName = tableName;
|
||||
this.TableDescription = tableDescription;
|
||||
}
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Property , Inherited = true)]
|
||||
public class SugarColumn : Attribute
|
||||
|
@ -63,18 +63,29 @@ namespace SqlSugar
|
||||
{
|
||||
if (_Result == null) return null;
|
||||
if (IsUpper)
|
||||
return _Result.ToString().ToUpper().TrimEnd(',');
|
||||
return _Result.ToString().ToUpper().Replace(UtilConstants.ReplaceCommaKey,",").TrimEnd(',');
|
||||
else
|
||||
return _Result.ToString().TrimEnd(',');
|
||||
return _Result.ToString().Replace(UtilConstants.ReplaceCommaKey, ",").TrimEnd(',');
|
||||
}
|
||||
#region functions
|
||||
public string[] GetResultArray()
|
||||
{
|
||||
if (this._Result == null) return null;
|
||||
var reslut = new List<string>();
|
||||
|
||||
if (IsUpper)
|
||||
return this.Result.ToString().ToUpper().TrimEnd(',').Split(',');
|
||||
reslut= this.Result.ToString().ToUpper().TrimEnd(',').Split(',').ToList();
|
||||
else
|
||||
return this.Result.ToString().TrimEnd(',').Split(',');
|
||||
reslut= this.Result.ToString().TrimEnd(',').Split(',').ToList();
|
||||
|
||||
if (this.Result.ToString().Contains(UtilConstants.ReplaceCommaKey))
|
||||
{
|
||||
for (int i = 0; i < reslut.Count; i++)
|
||||
{
|
||||
reslut[i] = reslut[i].Replace(UtilConstants.ReplaceCommaKey, ",");
|
||||
}
|
||||
}
|
||||
return reslut.ToArray();
|
||||
}
|
||||
|
||||
public string GetResultString()
|
||||
@ -82,12 +93,12 @@ namespace SqlSugar
|
||||
if (this._Result == null) return null;
|
||||
if (this._ResolveExpressType.IsIn(ResolveExpressType.SelectMultiple, ResolveExpressType.SelectSingle))
|
||||
{
|
||||
return this.Result.ToString().TrimEnd(',');
|
||||
return this.Result.ToString().Replace(UtilConstants.ReplaceCommaKey, ",").TrimEnd(',');
|
||||
}
|
||||
if (IsUpper)
|
||||
return this.Result.ToString().ToUpper();
|
||||
return this.Result.ToString().Replace(UtilConstants.ReplaceCommaKey, ",").ToUpper();
|
||||
else
|
||||
return this.Result.ToString();
|
||||
return this.Result.ToString().Replace(UtilConstants.ReplaceCommaKey, ",");
|
||||
}
|
||||
|
||||
public void TrimEnd()
|
||||
|
@ -91,6 +91,10 @@ namespace SqlSugar
|
||||
{
|
||||
this.DbType = System.Data.DbType.String;
|
||||
}
|
||||
else if (type == UtilConstants.DateTimeOffsetType)
|
||||
{
|
||||
this.DbType = System.Data.DbType.DateTimeOffset;
|
||||
}
|
||||
|
||||
}
|
||||
public SugarParameter(string name, object value, bool isOutput)
|
||||
|
@ -124,7 +124,7 @@ namespace SqlSugar
|
||||
{
|
||||
base.Expression = item;
|
||||
base.Start();
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString()));
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,11 @@ namespace SqlSugar
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
base.Context.Result.Append("," + parameter.CommonTempData.ObjToString() + ",");
|
||||
base.Context.Result.Append("," + parameter.CommonTempData.ObjToString().Replace(",",UtilConstants.ReplaceCommaKey) + ",");
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Context.Result.Append(parameter.CommonTempData.ObjToString() + ",");
|
||||
base.Context.Result.Append(parameter.CommonTempData.ObjToString().Replace(",", UtilConstants.ReplaceCommaKey) + ",");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
@ -269,6 +269,7 @@ namespace SqlSugar
|
||||
public SqlSugarClient CopyContext(bool isCopyEvents = false)
|
||||
{
|
||||
var newClient = new SqlSugarClient(this.TranslateCopy(Context.CurrentConnectionConfig));
|
||||
newClient.CurrentConnectionConfig.ConfigureExternalServices=Context.CurrentConnectionConfig.ConfigureExternalServices;
|
||||
newClient.MappingColumns = this.TranslateCopy(Context.MappingColumns);
|
||||
newClient.MappingTables = this.TranslateCopy(Context.MappingTables);
|
||||
newClient.IgnoreColumns = this.TranslateCopy(Context.IgnoreColumns);
|
||||
|
@ -247,13 +247,14 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Create Instance
|
||||
protected ISugarQueryable<T> CreateQueryable<T>() where T : class, new()
|
||||
protected ISugarQueryable<T> CreateQueryable<T>()
|
||||
{
|
||||
ISugarQueryable<T> result = InstanceFactory.GetQueryable<T>(this.CurrentConnectionConfig);
|
||||
return CreateQueryable(result);
|
||||
}
|
||||
protected ISugarQueryable<T> CreateQueryable<T>(ISugarQueryable<T> result) where T : class, new()
|
||||
protected ISugarQueryable<T> CreateQueryable<T>(ISugarQueryable<T> result)
|
||||
{
|
||||
Check.Exception(typeof(T).IsClass()==false|| typeof(T).GetConstructors().Length==0, "Queryable<{0}> Error ,{0} is invalid , need is a class,and can new().", typeof(T).Name);
|
||||
var sqlBuilder = InstanceFactory.GetSqlbuilder(CurrentConnectionConfig);
|
||||
result.Context = this.Context;
|
||||
result.SqlBuilder = sqlBuilder;
|
||||
@ -308,7 +309,7 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void CreateQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable) where T : class, new()
|
||||
protected void CreateQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable)
|
||||
{
|
||||
this.CreateQueryable<T>(queryable);
|
||||
string shortName = string.Empty;
|
||||
@ -321,7 +322,7 @@ namespace SqlSugar
|
||||
queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters);
|
||||
}
|
||||
}
|
||||
protected void CreateEasyQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable) where T : class, new()
|
||||
protected void CreateEasyQueryJoin<T>(Expression joinExpression, Type[] types, ISugarQueryable<T> queryable)
|
||||
{
|
||||
this.CreateQueryable<T>(queryable);
|
||||
string shortName = string.Empty;
|
||||
@ -342,6 +343,7 @@ namespace SqlSugar
|
||||
expressionContext.Resolve(joinExpression, ResolveExpressType.Join);
|
||||
int i = 0;
|
||||
var joinArray = MergeJoinArray(expressionContext.Result.GetResultArray());
|
||||
if (joinArray == null) return null;
|
||||
parameters = expressionContext.Parameters;
|
||||
foreach (var entityType in entityTypeArray)
|
||||
{
|
||||
@ -380,6 +382,7 @@ namespace SqlSugar
|
||||
List<string> result = new List<string>();
|
||||
string joinValue = null;
|
||||
int i = 0;
|
||||
if (joinArray == null) return null;
|
||||
foreach (var item in joinArray)
|
||||
{
|
||||
++i;
|
||||
|
@ -8,6 +8,7 @@ namespace SqlSugar
|
||||
{
|
||||
SqlSugarClient Context { get; set; }
|
||||
ICodeFirst BackupTable(int maxBackupDataRows=int.MaxValue);
|
||||
ICodeFirst SetStringDefaultLength(int length);
|
||||
void InitTables(string entitiesNamespace);
|
||||
void InitTables(string [] entitiesNamespaces);
|
||||
void InitTables(params Type [] entityTypes);
|
||||
|
@ -37,6 +37,13 @@ namespace SqlSugar
|
||||
bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue);
|
||||
bool DropColumn(string tableName,string columnName);
|
||||
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
|
||||
bool AddRemark(EntityInfo entity);
|
||||
bool AddColumnRemark(string columnName,string tableName,string description);
|
||||
bool DeleteColumnRemark(string columnName, string tableName);
|
||||
bool IsAnyColumnRemark(string columnName, string tableName);
|
||||
bool AddTableRemark( string tableName, string description);
|
||||
bool DeleteTableRemark(string tableName);
|
||||
bool IsAnyTableRemark(string tableName);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace SqlSugar
|
||||
SqlSugarClient Context { get; set; }
|
||||
ISqlBuilder SqlBuilder { get; set; }
|
||||
QueryBuilder QueryBuilder { get; set; }
|
||||
|
||||
ISugarQueryable<T> Clone();
|
||||
ISugarQueryable<T> AS<T2>(string tableName);
|
||||
ISugarQueryable<T> AS(string tableName);
|
||||
ISugarQueryable<T> With(string withString);
|
||||
@ -179,6 +179,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2> Clone();
|
||||
new ISugarQueryable<T, T2> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2> AS(string tableName);
|
||||
new ISugarQueryable<T, T2> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -246,6 +247,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3> Clone();
|
||||
new ISugarQueryable<T, T2, T3> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -320,6 +322,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -396,6 +399,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -470,6 +474,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -549,6 +554,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -633,6 +639,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -724,6 +731,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -818,6 +826,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -917,6 +926,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
@ -1021,6 +1031,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Clone();
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> AS<AsT>(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> AS(string tableName);
|
||||
new ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Filter(string FilterName, bool isDisabledGobalFilter = false);
|
||||
|
@ -38,6 +38,10 @@ namespace SqlSugar
|
||||
IUpdateable<T> UpdateColumns(Expression<Func<T, bool>> columns);
|
||||
IUpdateable<T> UpdateColumns(Func<string, bool> updateColumMethod);
|
||||
IUpdateable<T> UpdateColumns(Expression<Func<T, T>> columns);
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,Expression<Func<T, object>> columns);
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,Expression<Func<T, bool>> columns);
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,Func<string, bool> updateColumMethod);
|
||||
IUpdateable<T> UpdateColumnsIF(bool isUpdateColumns,Expression<Func<T, T>> columns);
|
||||
IUpdateable<T> IgnoreColumns(bool ignoreAllNullColumns, bool isOffIdentity = false);
|
||||
IUpdateable<T> IgnoreColumns(Expression<Func<T, object>> columns);
|
||||
IUpdateable<T> IgnoreColumns(Func<string, bool> ignoreColumMethod);
|
||||
|
@ -67,5 +67,10 @@ namespace SqlSugar
|
||||
if (item.IsPrimarykey)
|
||||
this.Context.DbMaintenance.AddPrimaryKey(tableName, item.DbColumnName);
|
||||
}
|
||||
|
||||
internal DbColumnInfo GetEntityColumnToDbColumn(EntityInfo entity, string dbTableName, EntityColumnInfo item)
|
||||
{
|
||||
return EntityColumnToDbColumn(entity,dbTableName,item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,9 +176,72 @@ namespace SqlSugar
|
||||
return "AUTO_INCREMENT";
|
||||
}
|
||||
}
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} COMMENT='{1}';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALTER TABLE {0} COMMENT='';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override bool AddRemark(EntityInfo entity)
|
||||
{
|
||||
var db = this.Context;
|
||||
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription);
|
||||
List<EntityColumnInfo> columns = entity.Columns.Where(it => it.IsIgnore == false).ToList();
|
||||
foreach (var item in columns)
|
||||
{
|
||||
if (item.ColumnDescription != null)
|
||||
{
|
||||
var mySqlCodeFirst = this.Context.CodeFirst as MySqlCodeFirst;
|
||||
string sql = GetUpdateColumnSql(entity.DbTableName, mySqlCodeFirst.GetEntityColumnToDbColumn(entity, entity.DbTableName, item)) + " " + (item.IsIdentity ? "AUTO_INCREMENT" : "") + " " + " COMMENT '" + item.ColumnDescription + "'";
|
||||
db.Ado.ExecuteCommand(sql);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
{
|
||||
if (columns.HasValue())
|
||||
|
@ -169,6 +169,53 @@ namespace SqlSugar
|
||||
return "IDENTITY(1,1)";
|
||||
}
|
||||
}
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "comment on column {1}.{0} is '{2}';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "comment on column {1}.{0} is '';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select * from user_col_comments where Table_Name='{1}' AND COLUMN_NAME='{0}' order by column_name";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "comment on table {0} is '{1}';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "comment on table {0} is '';";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select * from user_tab_comments where Table_Name='{0}'order by Table_Name";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
@ -200,6 +200,70 @@ namespace SqlSugar
|
||||
return "IDENTITY(1,1)";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "EXECUTE sp_addextendedproperty N'MS_Description', '{2}', N'user', N'dbo', N'table', N'{1}', N'column', N'{0}'"; ;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','{1}','column',{0}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override string IsAnyColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"SELECT" +
|
||||
" A.name AS table_name," +
|
||||
" B.name AS column_name," +
|
||||
" C.value AS column_description" +
|
||||
" FROM sys.tables A" +
|
||||
" LEFT JOIN sys.extended_properties C ON C.major_id = A.object_id" +
|
||||
" LEFT JOIN sys.columns B ON B.object_id = A.object_id AND C.minor_id = B.column_id" +
|
||||
" INNER JOIN sys.schemas SC ON SC.schema_id = A.schema_id AND SC.name = 'dbo'"+
|
||||
" WHERE A.name = '{1}' and b.name = '{0}'";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "EXECUTE sp_addextendedproperty N'MS_Description', '{1}', N'user', N'dbo', N'table', N'{0}', NULL, NULL";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','{0}' ";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override string IsAnyTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"SELECT C.class_desc
|
||||
FROM sys.tables A
|
||||
LEFT JOIN sys.extended_properties C ON C.major_id = A.object_id
|
||||
INNER JOIN sys.schemas SC ON SC.schema_id=A.schema_id AND SC.name='dbo'
|
||||
WHERE A.name = '{0}' AND minor_id=0";
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
||||
|
@ -162,9 +162,60 @@ namespace SqlSugar
|
||||
return "AUTOINCREMENT";
|
||||
}
|
||||
}
|
||||
protected override string AddColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyColumnRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string AddTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string DeleteTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string IsAnyTableRemarkSql
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override bool AddRemark(EntityInfo entity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName,bool isCache=true)
|
||||
{
|
||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||
|
@ -103,7 +103,7 @@ namespace SqlSugar
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>() where T : class, new()
|
||||
public virtual ISugarQueryable<T> Queryable<T>()
|
||||
{
|
||||
|
||||
InitMppingInfo<T>();
|
||||
@ -113,7 +113,7 @@ namespace SqlSugar
|
||||
/// <summary>
|
||||
/// Lambda Query operation
|
||||
/// </summary>
|
||||
public virtual ISugarQueryable<T> Queryable<T>(string shortName) where T : class, new()
|
||||
public virtual ISugarQueryable<T> Queryable<T>(string shortName)
|
||||
{
|
||||
var queryable = Queryable<T>();
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
@ -129,7 +129,7 @@ namespace SqlSugar
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2> Queryable<T, T2>(Expression<Func<T, T2, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2>();
|
||||
var types = new Type[] { typeof(T2) };
|
||||
@ -137,7 +137,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3> Queryable<T, T2, T3>(Expression<Func<T, T2, T3, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3) };
|
||||
@ -145,7 +145,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4> Queryable<T, T2, T3, T4>(Expression<Func<T, T2, T3, T4, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4) };
|
||||
@ -153,7 +153,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5> Queryable<T, T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5) };
|
||||
@ -161,7 +161,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6> Queryable<T, T2, T3, T4, T5, T6>(Expression<Func<T, T2, T3, T4, T5, T6, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6) };
|
||||
@ -169,7 +169,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7> Queryable<T, T2, T3, T4, T5, T6, T7>(Expression<Func<T, T2, T3, T4, T5, T6, T7, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7) };
|
||||
@ -177,7 +177,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8> Queryable<T, T2, T3, T4, T5, T6, T7, T8>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8) };
|
||||
@ -186,7 +186,7 @@ namespace SqlSugar
|
||||
return queryable;
|
||||
}
|
||||
#region 9-12
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9) };
|
||||
@ -194,7 +194,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10) };
|
||||
@ -202,7 +202,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11) };
|
||||
@ -210,7 +210,7 @@ namespace SqlSugar
|
||||
this.CreateQueryJoin(joinExpression, types, queryable);
|
||||
return queryable;
|
||||
}
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression) where T : class, new()
|
||||
public virtual ISugarQueryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Queryable<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Expression<Func<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, object[]>> joinExpression)
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>();
|
||||
var types = new Type[] { typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6), typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12) };
|
||||
@ -350,7 +350,7 @@ namespace SqlSugar
|
||||
var shortName1 = joinExpression.Parameters[0].Name;
|
||||
var sqlObj1 = joinQueryable1.ToSql();
|
||||
string sql1 = sqlObj1.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql1, sqlObj1.Value.ToArray(), 0);
|
||||
UtilMethods.RepairReplicationParameters(ref sql1, sqlObj1.Value.ToArray(), 0,"Join");
|
||||
queryable.QueryBuilder.EntityName = sqlBuilder.GetPackTable(sql1, shortName1); ;
|
||||
queryable.QueryBuilder.Parameters.AddRange(sqlObj1.Value);
|
||||
|
||||
@ -358,7 +358,7 @@ namespace SqlSugar
|
||||
var shortName2 = joinExpression.Parameters[1].Name;
|
||||
var sqlObj2 = joinQueryable2.ToSql();
|
||||
string sql2 = sqlObj2.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql2, sqlObj2.Value.ToArray(), 1);
|
||||
UtilMethods.RepairReplicationParameters(ref sql2, sqlObj2.Value.ToArray(), 1, "Join");
|
||||
queryable.QueryBuilder.Parameters.AddRange(sqlObj2.Value);
|
||||
var exp = queryable.QueryBuilder.GetExpressionValue(joinExpression, ResolveExpressType.WhereMultiple);
|
||||
queryable.QueryBuilder.JoinQueryInfos.Add(new JoinQueryInfo() { JoinIndex = 0, JoinType = joinType, JoinWhere = exp.GetResultString(), TableName = sqlBuilder.GetPackTable(sql2, shortName2) });
|
||||
@ -377,7 +377,7 @@ namespace SqlSugar
|
||||
{
|
||||
var sqlObj = item.ToSql();
|
||||
string sql = sqlObj.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i);
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i, "UnionAll");
|
||||
if (sqlObj.Value.HasValue())
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
|
||||
else
|
||||
@ -405,7 +405,7 @@ namespace SqlSugar
|
||||
{
|
||||
var sqlObj = item.ToSql();
|
||||
string sql = sqlObj.Key;
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i);
|
||||
UtilMethods.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), i, "Union");
|
||||
if (sqlObj.Value.HasValue())
|
||||
allItems.Add(new KeyValuePair<string, List<SugarParameter>>(sql, sqlObj.Value));
|
||||
else
|
||||
|
@ -13,6 +13,7 @@ namespace SqlSugar
|
||||
internal const char SpaceChar =' ';
|
||||
internal const string AssemblyName = "SqlSugar";
|
||||
internal const string ReplaceKey = "{662E689B-17A1-4D06-9D27-F29EAB8BC3D6}";
|
||||
internal const string ReplaceCommaKey = "{112A689B-17A1-4A06-9D27-A39EAB8BC3D5}";
|
||||
|
||||
internal static Type IntType = typeof(int);
|
||||
internal static Type LongType = typeof(long);
|
||||
@ -26,6 +27,7 @@ namespace SqlSugar
|
||||
internal static Type DecType = typeof(decimal);
|
||||
internal static Type StringType = typeof(string);
|
||||
internal static Type DateType = typeof(DateTime);
|
||||
internal static Type DateTimeOffsetType = typeof(DateTimeOffset);
|
||||
internal static Type ByteArrayType = typeof(byte[]);
|
||||
internal static Type ModelType= typeof(ModelContext);
|
||||
internal static Type DynamicType = typeof(ExpandoObject);
|
||||
|
@ -68,7 +68,7 @@ namespace SqlSugar
|
||||
return (T)Convert.ChangeType(obj, typeof(T));
|
||||
}
|
||||
|
||||
internal static void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex)
|
||||
internal static void RepairReplicationParameters(ref string appendSql, SugarParameter[] parameters, int addIndex,string append=null)
|
||||
{
|
||||
if (appendSql.HasValue() && parameters.HasValue())
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace SqlSugar
|
||||
{
|
||||
//Compatible with.NET CORE parameters case
|
||||
var name = parameter.ParameterName;
|
||||
string newName = name + addIndex;
|
||||
string newName = name +append+ addIndex;
|
||||
appendSql = appendSql.Replace(name, newName);
|
||||
parameter.ParameterName = newName;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user