mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
Add Ccheck , Dbfirst and Codefirst requires system table permissions
This commit is contained in:
@@ -22,6 +22,10 @@ namespace SqlSugar
|
||||
}
|
||||
public void InitTables(Type entityType)
|
||||
{
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions())
|
||||
{
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
}
|
||||
Check.Exception(this.Context.IsSystemTablesConfig, "Please set SqlSugarClent Parameter ConnectionConfig.InitKeyType=InitKeyType.Attribute ");
|
||||
var executeResult = Context.Ado.UseTran(() =>
|
||||
{
|
||||
|
@@ -39,6 +39,9 @@ namespace SqlSugar
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (!this.Context.DbMaintenance.IsAnySystemTablePermissions()) {
|
||||
Check.Exception(true, "Dbfirst and Codefirst requires system table permissions");
|
||||
}
|
||||
this.TableInfoList =this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetTableInfoList());
|
||||
var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList());
|
||||
if (viewList.IsValuable())
|
||||
|
@@ -99,6 +99,19 @@ namespace SqlSugar
|
||||
{
|
||||
return this.Context.Ado.GetInt("select object_id('" + constraintName + "')") > 0;
|
||||
}
|
||||
public virtual bool IsAnySystemTablePermissions()
|
||||
{
|
||||
string sql = this.CheckSystemTablePermissionsSql;
|
||||
try
|
||||
{
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
|
@@ -32,6 +32,10 @@ namespace SqlSugar
|
||||
protected abstract string RenameColumnSql { get; }
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected abstract string CheckSystemTablePermissionsSql { get; }
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected abstract string CreateTableNull { get; }
|
||||
protected abstract string CreateTableNotNull { get; }
|
||||
|
@@ -22,6 +22,7 @@ namespace SqlSugar
|
||||
bool IsPrimaryKey(string tableName, string column);
|
||||
bool IsIdentity(string tableName, string column);
|
||||
bool IsAnyConstraint(string ConstraintName);
|
||||
bool IsAnySystemTablePermissions();
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
|
@@ -152,13 +152,25 @@ namespace SqlSugar
|
||||
return "ALTER TABLE {0} DROP CONSTRAINT {1}";
|
||||
}
|
||||
}
|
||||
protected override string RenameColumnSql {
|
||||
get {
|
||||
protected override string RenameColumnSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "exec sp_rename '{0}.{1}','{2}','column';";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Check
|
||||
protected override string CheckSystemTablePermissionsSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "select top 1 id from sysobjects";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Scattered
|
||||
protected override string CreateTableNull
|
||||
{
|
||||
|
Reference in New Issue
Block a user