mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Update SqlServer IsAnyTable
This commit is contained in:
parent
c133dcac08
commit
b0323a90d3
@ -52,6 +52,13 @@ namespace OrmTest
|
||||
catch
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
Db.Ado.ExecuteCommand(@" create schema [ddd]");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
db.CodeFirst.InitTables<UnitTableName>();
|
||||
db.CodeFirst.InitTables<UnitGe>();
|
||||
db.Insertable(new UnitGe() { geometry1 = "POINT (20 180)" }).ExecuteCommand();
|
||||
@ -67,6 +74,7 @@ namespace OrmTest
|
||||
Db.CodeFirst.InitTables<UNITCODEFIRST131>();
|
||||
Db.CodeFirst.InitTables<UNITCOdEFIRST131>();
|
||||
Db.CodeFirst.InitTables<UnitTableUserName>();
|
||||
db.CodeFirst.InitTables<UnitTablename>();
|
||||
}
|
||||
public class UnitCodeFirst131
|
||||
{
|
||||
@ -104,7 +112,11 @@ namespace OrmTest
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
[SugarTable("ddd.UnitTableName", "备注")]
|
||||
public class UnitTablename
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
public class UnitDateOfTime2
|
||||
{
|
||||
|
||||
|
@ -313,6 +313,28 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override bool IsAnyTable(string tableName, bool isCache = true)
|
||||
{
|
||||
if (tableName.Contains("."))
|
||||
{
|
||||
var schemas = GetSchemas();
|
||||
var first =this.SqlBuilder.GetNoTranslationColumnName(tableName.Split('.').First());
|
||||
var schemaInfo= schemas.FirstOrDefault(it=>it.EqualCase(first));
|
||||
if (schemaInfo == null)
|
||||
{
|
||||
return base.IsAnyTable(tableName, isCache);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result= this.Context.Ado.GetInt($"select object_id('{tableName}')");
|
||||
return result > 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.IsAnyTable(tableName, isCache);
|
||||
}
|
||||
}
|
||||
public List<string> GetSchemas()
|
||||
{
|
||||
return this.Context.Ado.SqlQuery<string>("SELECT name FROM sys.schemas where name <> 'dbo'");
|
||||
|
Loading…
Reference in New Issue
Block a user