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)
{
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(() =>
{

View File

@@ -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())

View File

@@ -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

View File

@@ -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; }

View File

@@ -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

View File

@@ -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
{