mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
Merge branch 'dev' of github.com:sunkaixuan/SqlSugar
# Conflicts: # Src/Asp.Net/SqlSugar/Properties/AssemblyInfo.cs # Src/Asp.Net/SqlSugar/SqlSugar.nuspec
This commit is contained in:
20
README.md
20
README.md
@@ -55,6 +55,26 @@ var skip5 = db.Queryable<Student>().Skip(5).ToList();
|
|||||||
```
|
```
|
||||||
|
|
||||||
### 1.4 Join
|
### 1.4 Join
|
||||||
|
|
||||||
|
#### easy join
|
||||||
|
```c
|
||||||
|
//2 join
|
||||||
|
var list5 = db.Queryable<Student, School>((st, sc) => st.SchoolId == sc.Id).Select((st,sc)=>new {st.Name,st.Id,schoolName=sc.Name}).ToList();
|
||||||
|
```
|
||||||
|
|
||||||
|
```c
|
||||||
|
//3 join
|
||||||
|
var list6 = db.Queryable<Student, School,School>((st, sc,sc2) => st.SchoolId == sc.Id&&sc.Id==sc2.Id)
|
||||||
|
.Select((st, sc,sc2) => new { st.Name, st.Id, schoolName = sc.Name,schoolName2=sc2.Name }).ToList();
|
||||||
|
```
|
||||||
|
|
||||||
|
```c
|
||||||
|
//3 join page
|
||||||
|
var list7= db.Queryable<Student, School, School>((st, sc, sc2) => st.SchoolId == sc.Id && sc.Id == sc2.Id)
|
||||||
|
.Select((st, sc, sc2) => new { st.Name, st.Id, schoolName = sc.Name, schoolName2 = sc2.Name }).ToPageList(1,2);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### left join
|
||||||
```c
|
```c
|
||||||
//join 2
|
//join 2
|
||||||
var list = db.Queryable<Student, School>((st, sc) => new object[] {
|
var list = db.Queryable<Student, School>((st, sc) => new object[] {
|
||||||
|
@@ -164,7 +164,7 @@ namespace OrmTest.Demo
|
|||||||
var getFirstOrDefault = db.Queryable<Student>().First();
|
var getFirstOrDefault = db.Queryable<Student>().First();
|
||||||
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
|
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
|
||||||
var getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
|
var getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();
|
||||||
var sum = db.Queryable<Student>().Sum(it => it.Id);
|
var sum = db.Queryable<Student>().Select(it => it.SchoolId).ToList();
|
||||||
var sum2 = db.Queryable<Student,School>((st,sc)=>st.SchoolId==sc.Id).Sum((st,sc) => sc.Id);
|
var sum2 = db.Queryable<Student,School>((st,sc)=>st.SchoolId==sc.Id).Sum((st,sc) => sc.Id);
|
||||||
var isAny = db.Queryable<Student>().Where(it => it.Id == -1).Any();
|
var isAny = db.Queryable<Student>().Where(it => it.Id == -1).Any();
|
||||||
var isAny2 = db.Queryable<Student>().Any(it => it.Id == -1);
|
var isAny2 = db.Queryable<Student>().Any(it => it.Id == -1);
|
||||||
|
@@ -135,7 +135,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reval.Add((T)Convert.ChangeType(re.GetValue(0), type));
|
reval.Add((T)Convert.ChangeType(re.GetValue(0),PubMethod.GetUnderType(type)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,8 +10,9 @@ namespace SqlSugar
|
|||||||
#region DML
|
#region DML
|
||||||
public virtual List<DbTableInfo> GetViewInfoList()
|
public virtual List<DbTableInfo> GetViewInfoList()
|
||||||
{
|
{
|
||||||
string key = "DbMaintenanceProvider.GetViewInfoList";
|
string cacheKey = "DbMaintenanceProvider.GetViewInfoList";
|
||||||
var result = GetListOrCache<DbTableInfo>(key, this.GetViewInfoListSql);
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetViewInfoListSql);
|
||||||
foreach (var item in result)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
item.DbObjectType = DbObjectType.View;
|
item.DbObjectType = DbObjectType.View;
|
||||||
@@ -20,8 +21,9 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual List<DbTableInfo> GetTableInfoList()
|
public virtual List<DbTableInfo> GetTableInfoList()
|
||||||
{
|
{
|
||||||
string key = "DbMaintenanceProvider.GetTableInfoList";
|
string cacheKey = "DbMaintenanceProvider.GetTableInfoList";
|
||||||
var result = GetListOrCache<DbTableInfo>(key, this.GetTableInfoListSql);
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetTableInfoListSql);
|
||||||
foreach (var item in result)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
item.DbObjectType = DbObjectType.Table;
|
item.DbObjectType = DbObjectType.Table;
|
||||||
@@ -31,12 +33,14 @@ namespace SqlSugar
|
|||||||
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
||||||
string key = "DbMaintenanceProvider.GetColumnInfosByTableName." +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
return GetListOrCache<DbColumnInfo>(key, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
return GetListOrCache<DbColumnInfo>(cacheKey, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
||||||
}
|
}
|
||||||
public virtual List<string> GetIsIdentities(string tableName)
|
public virtual List<string> GetIsIdentities(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetIsIdentities" +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetIsIdentities" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
@@ -50,7 +54,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual List<string> GetPrimaries(string tableName)
|
public virtual List<string> GetPrimaries(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetPrimaries" +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetPrimaries" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
@@ -108,6 +113,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.Context.Ado.CheckConnection();
|
this.Context.Ado.CheckConnection();
|
||||||
string sql = this.CheckSystemTablePermissionsSql;
|
string sql = this.CheckSystemTablePermissionsSql;
|
||||||
|
this.Context.Ado.CheckConnection();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||||
@@ -127,8 +133,8 @@ namespace SqlSugar
|
|||||||
public virtual bool AddPrimaryKey(string tableName, string columnName)
|
public virtual bool AddPrimaryKey(string tableName, string columnName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
columnName=this.SqlBuilder.GetTranslationTableName(columnName);
|
columnName = this.SqlBuilder.GetTranslationTableName(columnName);
|
||||||
string sql = string.Format(this.AddPrimaryKeySql,tableName, string.Format("PK_{0}_{1}",this.SqlBuilder.GetNoTranslationColumnName(tableName), this.SqlBuilder.GetNoTranslationColumnName(columnName)), columnName);
|
string sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName), this.SqlBuilder.GetNoTranslationColumnName(columnName)), columnName);
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -156,7 +162,7 @@ namespace SqlSugar
|
|||||||
public virtual bool DropTable(string tableName)
|
public virtual bool DropTable(string tableName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
this.Context.Ado.ExecuteCommand(string.Format(this.DropTableSql,tableName));
|
this.Context.Ado.ExecuteCommand(string.Format(this.DropTableSql, tableName));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public virtual bool DropColumn(string tableName, string columnName)
|
public virtual bool DropColumn(string tableName, string columnName)
|
||||||
@@ -193,7 +199,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
||||||
newTableName = this.SqlBuilder.GetTranslationTableName(newTableName);
|
newTableName = this.SqlBuilder.GetTranslationTableName(newTableName);
|
||||||
string sql = string.Format(this.BackupTableSql,newTableName , oldTableName, maxBackupDataRows);
|
string sql = string.Format(this.BackupTableSql, newTableName, oldTableName, maxBackupDataRows);
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -231,21 +237,21 @@ namespace SqlSugar
|
|||||||
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
||||||
foreach (var item in columns)
|
foreach (var item in columns)
|
||||||
{
|
{
|
||||||
string columnName =this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
|
||||||
string dataType = item.DataType;
|
string dataType = item.DataType;
|
||||||
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
||||||
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
||||||
string primaryKey = null;
|
string primaryKey = null;
|
||||||
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
|
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
|
||||||
string addItem = string.Format(this.CreateTableColumn,columnName, dataType, dataSize, nullType, primaryKey, identity);
|
string addItem = string.Format(this.CreateTableColumn, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
||||||
columnArray.Add(addItem);
|
columnArray.Add(addItem);
|
||||||
}
|
}
|
||||||
string tableString = string.Format(this.CreateTableSql,this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
||||||
return tableString;
|
return tableString;
|
||||||
}
|
}
|
||||||
protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo)
|
protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo)
|
||||||
{
|
{
|
||||||
string columnName=this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
string dataType = columnInfo.DataType;
|
string dataType = columnInfo.DataType;
|
||||||
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
||||||
@@ -257,7 +263,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
protected virtual string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
|
protected virtual string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
|
||||||
{
|
{
|
||||||
string columnName =this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
string dataType = columnInfo.DataType;
|
string dataType = columnInfo.DataType;
|
||||||
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
||||||
@@ -267,6 +273,10 @@ namespace SqlSugar
|
|||||||
string result = string.Format(this.AlterColumnToTableSql, tableName, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
string result = string.Format(this.AlterColumnToTableSql, tableName, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
protected virtual string GetCacheKey(string cacheKey)
|
||||||
|
{
|
||||||
|
return this.Context.CurrentConnectionConfig.DbType + "." + this.Context.Ado.Connection.Database +"."+ cacheKey;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("4.2.1.2")]
|
[assembly: AssemblyVersion("4.2.1.6")]
|
||||||
[assembly: AssemblyFileVersion("4.2.1.2")]
|
[assembly: AssemblyFileVersion("4.2.1.6")]
|
||||||
|
@@ -167,6 +167,7 @@ namespace SqlSugar
|
|||||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<DbColumnInfo>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<DbColumnInfo>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>sqlSugar</id>
|
<id>sqlSugar</id>
|
||||||
<version>4.2.1.2</version>
|
<version>4.2.1.6</version>
|
||||||
<title>SqlSugar SqlServer ORM</title>
|
<title>SqlSugar SqlServer ORM</title>
|
||||||
<authors>sun kaixuan</authors>
|
<authors>sun kaixuan</authors>
|
||||||
<owners>landa</owners>
|
<owners>landa</owners>
|
||||||
|
Binary file not shown.
@@ -10,8 +10,9 @@ namespace SqlSugar
|
|||||||
#region DML
|
#region DML
|
||||||
public virtual List<DbTableInfo> GetViewInfoList()
|
public virtual List<DbTableInfo> GetViewInfoList()
|
||||||
{
|
{
|
||||||
string key = "DbMaintenanceProvider.GetViewInfoList";
|
string cacheKey = "DbMaintenanceProvider.GetViewInfoList";
|
||||||
var result = GetListOrCache<DbTableInfo>(key, this.GetViewInfoListSql);
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetViewInfoListSql);
|
||||||
foreach (var item in result)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
item.DbObjectType = DbObjectType.View;
|
item.DbObjectType = DbObjectType.View;
|
||||||
@@ -20,8 +21,9 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual List<DbTableInfo> GetTableInfoList()
|
public virtual List<DbTableInfo> GetTableInfoList()
|
||||||
{
|
{
|
||||||
string key = "DbMaintenanceProvider.GetTableInfoList";
|
string cacheKey = "DbMaintenanceProvider.GetTableInfoList";
|
||||||
var result = GetListOrCache<DbTableInfo>(key, this.GetTableInfoListSql);
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
var result = GetListOrCache<DbTableInfo>(cacheKey, this.GetTableInfoListSql);
|
||||||
foreach (var item in result)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
item.DbObjectType = DbObjectType.Table;
|
item.DbObjectType = DbObjectType.Table;
|
||||||
@@ -31,12 +33,14 @@ namespace SqlSugar
|
|||||||
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
||||||
string key = "DbMaintenanceProvider.GetColumnInfosByTableName." +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
return GetListOrCache<DbColumnInfo>(key, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
|
return GetListOrCache<DbColumnInfo>(cacheKey, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
||||||
}
|
}
|
||||||
public virtual List<string> GetIsIdentities(string tableName)
|
public virtual List<string> GetIsIdentities(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetIsIdentities" +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetIsIdentities" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
@@ -50,7 +54,8 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public virtual List<string> GetPrimaries(string tableName)
|
public virtual List<string> GetPrimaries(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetPrimaries" +this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetPrimaries" + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<string>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
@@ -107,11 +112,11 @@ namespace SqlSugar
|
|||||||
public virtual bool IsAnySystemTablePermissions()
|
public virtual bool IsAnySystemTablePermissions()
|
||||||
{
|
{
|
||||||
string sql = this.CheckSystemTablePermissionsSql;
|
string sql = this.CheckSystemTablePermissionsSql;
|
||||||
|
this.Context.Ado.CheckConnection();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
var oldIsEnableLog = this.Context.Ado.IsEnableLogEvent;
|
||||||
this.Context.Ado.IsEnableLogEvent = false;
|
this.Context.Ado.IsEnableLogEvent = false;
|
||||||
this.Context.Ado.CheckConnection();
|
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
this.Context.Ado.IsEnableLogEvent = oldIsEnableLog;
|
||||||
return true;
|
return true;
|
||||||
@@ -127,8 +132,8 @@ namespace SqlSugar
|
|||||||
public virtual bool AddPrimaryKey(string tableName, string columnName)
|
public virtual bool AddPrimaryKey(string tableName, string columnName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
columnName=this.SqlBuilder.GetTranslationTableName(columnName);
|
columnName = this.SqlBuilder.GetTranslationTableName(columnName);
|
||||||
string sql = string.Format(this.AddPrimaryKeySql,tableName, string.Format("PK_{0}_{1}",this.SqlBuilder.GetNoTranslationColumnName(tableName), this.SqlBuilder.GetNoTranslationColumnName(columnName)), columnName);
|
string sql = string.Format(this.AddPrimaryKeySql, tableName, string.Format("PK_{0}_{1}", this.SqlBuilder.GetNoTranslationColumnName(tableName), this.SqlBuilder.GetNoTranslationColumnName(columnName)), columnName);
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -156,7 +161,7 @@ namespace SqlSugar
|
|||||||
public virtual bool DropTable(string tableName)
|
public virtual bool DropTable(string tableName)
|
||||||
{
|
{
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
this.Context.Ado.ExecuteCommand(string.Format(this.DropTableSql,tableName));
|
this.Context.Ado.ExecuteCommand(string.Format(this.DropTableSql, tableName));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public virtual bool DropColumn(string tableName, string columnName)
|
public virtual bool DropColumn(string tableName, string columnName)
|
||||||
@@ -193,7 +198,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
oldTableName = this.SqlBuilder.GetTranslationTableName(oldTableName);
|
||||||
newTableName = this.SqlBuilder.GetTranslationTableName(newTableName);
|
newTableName = this.SqlBuilder.GetTranslationTableName(newTableName);
|
||||||
string sql = string.Format(this.BackupTableSql,newTableName , oldTableName, maxBackupDataRows);
|
string sql = string.Format(this.BackupTableSql, newTableName, oldTableName, maxBackupDataRows);
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -231,21 +236,21 @@ namespace SqlSugar
|
|||||||
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
||||||
foreach (var item in columns)
|
foreach (var item in columns)
|
||||||
{
|
{
|
||||||
string columnName =this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationTableName(item.DbColumnName);
|
||||||
string dataType = item.DataType;
|
string dataType = item.DataType;
|
||||||
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
string dataSize = item.Length > 0 ? string.Format("({0})", item.Length) : null;
|
||||||
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
string nullType = item.IsNullable ? this.CreateTableNull : CreateTableNotNull;
|
||||||
string primaryKey = null;
|
string primaryKey = null;
|
||||||
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
|
string identity = item.IsIdentity ? this.CreateTableIdentity : null;
|
||||||
string addItem = string.Format(this.CreateTableColumn,columnName, dataType, dataSize, nullType, primaryKey, identity);
|
string addItem = string.Format(this.CreateTableColumn, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
||||||
columnArray.Add(addItem);
|
columnArray.Add(addItem);
|
||||||
}
|
}
|
||||||
string tableString = string.Format(this.CreateTableSql,this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName), string.Join(",\r\n", columnArray));
|
||||||
return tableString;
|
return tableString;
|
||||||
}
|
}
|
||||||
protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo)
|
protected virtual string GetAddColumnSql(string tableName, DbColumnInfo columnInfo)
|
||||||
{
|
{
|
||||||
string columnName=this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
string dataType = columnInfo.DataType;
|
string dataType = columnInfo.DataType;
|
||||||
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
||||||
@@ -257,7 +262,7 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
protected virtual string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
|
protected virtual string GetUpdateColumnSql(string tableName, DbColumnInfo columnInfo)
|
||||||
{
|
{
|
||||||
string columnName =this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
|
string columnName = this.SqlBuilder.GetTranslationTableName(columnInfo.DbColumnName);
|
||||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||||
string dataType = columnInfo.DataType;
|
string dataType = columnInfo.DataType;
|
||||||
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
string dataSize = columnInfo.Length > 0 ? string.Format("({0})", columnInfo.Length) : null;
|
||||||
@@ -267,6 +272,10 @@ namespace SqlSugar
|
|||||||
string result = string.Format(this.AlterColumnToTableSql, tableName, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
string result = string.Format(this.AlterColumnToTableSql, tableName, columnName, dataType, dataSize, nullType, primaryKey, identity);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
protected virtual string GetCacheKey(string cacheKey)
|
||||||
|
{
|
||||||
|
return this.Context.CurrentConnectionConfig.DbType + "." + this.Context.Ado.Connection.Database +"."+ cacheKey;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,5 +17,5 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")]
|
[assembly: Guid("1c022a5c-4e4d-4026-a8a3-f659b9740a1a")]
|
||||||
[assembly: AssemblyVersion("4.2.1.1")]
|
[assembly: AssemblyVersion("4.2.1.5")]
|
||||||
[assembly: AssemblyFileVersion("4.2.1.1")]
|
[assembly: AssemblyFileVersion("4.2.1.5")]
|
||||||
|
@@ -168,6 +168,7 @@ namespace SqlSugar
|
|||||||
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
public override List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||||
{
|
{
|
||||||
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
string cacheKey = "DbMaintenanceProvider.GetColumnInfosByTableName." + this.SqlBuilder.GetNoTranslationColumnName(tableName).ToLower();
|
||||||
|
cacheKey = GetCacheKey(cacheKey);
|
||||||
return this.Context.RewritableMethods.GetCacheInstance<List<DbColumnInfo>>().Func(cacheKey,
|
return this.Context.RewritableMethods.GetCacheInstance<List<DbColumnInfo>>().Func(cacheKey,
|
||||||
(cm, key) =>
|
(cm, key) =>
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>sqlSugarCore</id>
|
<id>sqlSugarCore</id>
|
||||||
<version>4.2.1.1</version>
|
<version>4.2.1.5</version>
|
||||||
<authors>sunkaixuan</authors>
|
<authors>sunkaixuan</authors>
|
||||||
<owners>Landa</owners>
|
<owners>Landa</owners>
|
||||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||||
@@ -26,6 +26,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
<file src="D:\MyGit\SqlSugar\Src\Asp.NetCore\SqlServerTest\src\SqlSugar\bin\Debug\netstandard1.6\SqlSugar.dll" target="lib\netstandard1.6"></file>
|
<file src="F:\MyOpenSource\SqlSugar4.XNew\SqlSugar\Src\Asp.NetCore\SqlServerTest\src\SqlSugar\bin\Debug\netstandard1.6\SqlSugar.dll" target="lib\netstandard1.6"></file>
|
||||||
</files>
|
</files>
|
||||||
</package>
|
</package>
|
Reference in New Issue
Block a user