mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Sqlserver schema support
This commit is contained in:
parent
d8c4ff2395
commit
c927b530b4
@ -37,6 +37,20 @@ namespace OrmTest
|
||||
Db.Insertable(new List<UnitDateOfTime2> { new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime2() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
|
||||
var list2 = Db.Queryable<UnitDateOfTime2>().ToList();
|
||||
|
||||
try
|
||||
{
|
||||
Db.Ado.ExecuteCommand(@" create schema abp");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
db.CodeFirst.InitTables<UnitTableName>();
|
||||
|
||||
}
|
||||
[SugarTable("abp.UnitTableName","备注")]
|
||||
public class UnitTableName
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class UnitDateOfTime2
|
||||
|
@ -14,7 +14,16 @@ namespace SqlSugar
|
||||
var noFormat = table.Split(']').Length==1;
|
||||
if (tableArray.Length > 1 && noFormat)
|
||||
{
|
||||
return tableArray.Last();
|
||||
var dbMain = new SqlServerDbMaintenance() { Context = this.Context };
|
||||
var schmes = dbMain.GetSchemas();
|
||||
if (!schmes.Any(it => it.EqualCase(tableArray.First())))
|
||||
{
|
||||
return tableArray.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
return dbMain.SqlBuilder.GetTranslationTableName(table);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -313,6 +313,58 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public List<string> GetSchemas()
|
||||
{
|
||||
return this.Context.Ado.SqlQuery<string>("SELECT name FROM sys.schemas where name <> 'dbo'");
|
||||
}
|
||||
public override bool DeleteTableRemark(string tableName)
|
||||
{
|
||||
string sql = string.Format(this.DeleteTableRemarkSql, tableName);
|
||||
if (tableName.Contains("."))
|
||||
{
|
||||
var schemas = GetSchemas();
|
||||
var tableSchemas = this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').First());
|
||||
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
||||
{
|
||||
sql = string.Format(this.DeleteTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()));
|
||||
sql = sql.Replace(",dbo,", $",{tableSchemas},").Replace("'user'", "'SCHEMA'");
|
||||
}
|
||||
}
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public override bool IsAnyTableRemark(string tableName)
|
||||
{
|
||||
string sql = string.Format(this.IsAnyTableRemarkSql, tableName);
|
||||
if (tableName.Contains("."))
|
||||
{
|
||||
var schemas = GetSchemas();
|
||||
var tableSchemas = this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').First());
|
||||
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
||||
{
|
||||
sql = string.Format(this.IsAnyTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()));
|
||||
sql = sql.Replace("'dbo'", $"'{tableSchemas}'");
|
||||
}
|
||||
}
|
||||
var dt = this.Context.Ado.GetDataTable(sql);
|
||||
return dt.Rows != null && dt.Rows.Count > 0;
|
||||
}
|
||||
public override bool AddTableRemark(string tableName, string description)
|
||||
{
|
||||
string sql = string.Format(this.AddTableRemarkSql, tableName, description);
|
||||
if (tableName.Contains("."))
|
||||
{
|
||||
var schemas = GetSchemas();
|
||||
var tableSchemas =this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').First());
|
||||
if (schemas.Any(y => y.EqualCase(tableSchemas)))
|
||||
{
|
||||
sql = string.Format(this.AddTableRemarkSql, this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').Last()), description);
|
||||
sql = sql.Replace("N'dbo'", $"N'{tableSchemas}'").Replace("N'user'", "N'SCHEMA'");
|
||||
}
|
||||
}
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
public override bool AddDefaultValue(string tableName, string columnName, string defaultValue)
|
||||
{
|
||||
if (defaultValue == "''")
|
||||
|
Loading…
Reference in New Issue
Block a user