Browse Source

Add db.DbMain.IsPrimaryKey(+2)

SqlSugar5
sunkaixuan 2 years ago
parent
commit
851879a58b
  1. 10
      Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs
  2. 1
      Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs

10
Src/Asp.Net/SqlSugar/Abstract/DbMaintenanceProvider/Methods.cs

@ -106,6 +106,16 @@ namespace SqlSugar
var result=columns.Any(it => it.IsPrimarykey == true && it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
return result;
}
public virtual bool IsPrimaryKey(string tableName, string columnName,bool isCache=true)
{
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);
var isAny = IsAnyTable(tableName, isCache);
Check.Exception(!isAny, string.Format("Table {0} does not exist", tableName));
var columns = GetColumnInfosByTableName(tableName,isCache);
if (columns.IsNullOrEmpty()) return false;
var result = columns.Any(it => it.IsPrimarykey == true && it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
return result;
}
public virtual bool IsIdentity(string tableName, string columnName)
{
columnName = this.SqlBuilder.GetNoTranslationColumnName(columnName);

1
Src/Asp.Net/SqlSugar/Interface/IDbMaintenance.cs

@ -21,6 +21,7 @@ namespace SqlSugar
bool IsAnyTable(string tableName, bool isCache = true);
bool IsAnyColumn(string tableName, string column, bool isCache = true);
bool IsPrimaryKey(string tableName, string column);
bool IsPrimaryKey(string tableName, string column,bool isCache=true);
bool IsIdentity(string tableName, string column);
bool IsAnyConstraint(string ConstraintName);
bool IsAnySystemTablePermissions();

Loading…
Cancel
Save