Add Ccheck , Dbfirst and Codefirst requires system table permissions

This commit is contained in:
sunkaixuan
2017-06-20 14:39:17 +08:00
parent 889329d3a2
commit 1ea307d5f2
6 changed files with 39 additions and 2 deletions

View File

@@ -22,6 +22,10 @@ namespace SqlSugar
} }
public void InitTables(Type entityType) 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 "); Check.Exception(this.Context.IsSystemTablesConfig, "Please set SqlSugarClent Parameter ConnectionConfig.InitKeyType=InitKeyType.Attribute ");
var executeResult = Context.Ado.UseTran(() => var executeResult = Context.Ado.UseTran(() =>
{ {

View File

@@ -39,6 +39,9 @@ namespace SqlSugar
public void Init() 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()); this.TableInfoList =this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetTableInfoList());
var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList()); var viewList = this.Context.RewritableMethods.TranslateCopy(this.Context.DbMaintenance.GetViewInfoList());
if (viewList.IsValuable()) if (viewList.IsValuable())

View File

@@ -99,6 +99,19 @@ namespace SqlSugar
{ {
return this.Context.Ado.GetInt("select object_id('" + constraintName + "')") > 0; 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 #endregion
#region DDL #region DDL

View File

@@ -32,6 +32,10 @@ namespace SqlSugar
protected abstract string RenameColumnSql { get; } protected abstract string RenameColumnSql { get; }
#endregion #endregion
#region Check
protected abstract string CheckSystemTablePermissionsSql { get; }
#endregion
#region Scattered #region Scattered
protected abstract string CreateTableNull { get; } protected abstract string CreateTableNull { get; }
protected abstract string CreateTableNotNull { get; } protected abstract string CreateTableNotNull { get; }

View File

@@ -22,6 +22,7 @@ namespace SqlSugar
bool IsPrimaryKey(string tableName, string column); bool IsPrimaryKey(string tableName, string column);
bool IsIdentity(string tableName, string column); bool IsIdentity(string tableName, string column);
bool IsAnyConstraint(string ConstraintName); bool IsAnyConstraint(string ConstraintName);
bool IsAnySystemTablePermissions();
#endregion #endregion
#region DDL #region DDL

View File

@@ -152,13 +152,25 @@ namespace SqlSugar
return "ALTER TABLE {0} DROP CONSTRAINT {1}"; return "ALTER TABLE {0} DROP CONSTRAINT {1}";
} }
} }
protected override string RenameColumnSql { protected override string RenameColumnSql
get { {
get
{
return "exec sp_rename '{0}.{1}','{2}','column';"; return "exec sp_rename '{0}.{1}','{2}','column';";
} }
} }
#endregion #endregion
#region Check
protected override string CheckSystemTablePermissionsSql
{
get
{
return "select top 1 id from sysobjects";
}
}
#endregion
#region Scattered #region Scattered
protected override string CreateTableNull protected override string CreateTableNull
{ {