CodeFirst Support Column Description

This commit is contained in:
sunkaixuan 2018-11-11 13:15:18 +08:00
parent 76c87d796f
commit 0f99c6f20a
7 changed files with 52 additions and 1 deletions

View File

@ -6,10 +6,12 @@ using System.Text;
namespace OrmTest.Demo
{
[SugarTable("CodeTable", " table CodeTable")]
public class CodeTable
{
[SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true)]
[SugarColumn(IsNullable =false ,IsPrimaryKey =true,IsIdentity =true,ColumnDescription ="XXhaha primary key!!")]
public int Id { get; set; }
[SugarColumn(Length = 21,OldColumnName = "Name2")]
public string Name{ get; set; }

View File

@ -73,6 +73,8 @@ namespace SqlSugar
ExistLogic(entityInfo);
else
NoExistLogic(entityInfo);
this.Context.DbMaintenance.AddRemark(entityInfo);
}
public virtual void NoExistLogic(EntityInfo entityInfo)
{

View File

@ -60,6 +60,44 @@ namespace SqlSugar
protected abstract string CreateTableNotNull { get; }
protected abstract string CreateTablePirmaryKey { get; }
protected abstract string CreateTableIdentity { get; }
public virtual bool AddRemark(EntityInfo entity)
{
var db = this.Context;
var columns = entity.Columns.Where(it => it.IsIgnore == false).ToList();
foreach (var item in columns)
{
if (item.ColumnDescription != null)
{
//column remak
if (db.DbMaintenance.IsAnyColumnRemark(item.DbColumnName, item.DbTableName))
{
db.DbMaintenance.DeleteColumnRemark(item.DbColumnName, item.DbTableName);
db.DbMaintenance.AddColumnRemark(item.DbColumnName, item.DbTableName, item.ColumnDescription);
}
else
{
db.DbMaintenance.AddColumnRemark(item.DbColumnName, item.DbTableName, item.ColumnDescription);
}
}
}
//table remak
if (entity.TableDescription != null)
{
if (db.DbMaintenance.IsAnyTableRemark(entity.DbTableName))
{
db.DbMaintenance.DeleteTableRemark(entity.DbTableName);
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription);
}
else
{
db.DbMaintenance.AddTableRemark(entity.DbTableName, entity.TableDescription);
}
}
return true;
}
#endregion
}
}

View File

@ -27,6 +27,7 @@ namespace SqlSugar
{
var sugarTable = (SugarTable)sugarAttributeInfo;
result.DbTableName = sugarTable.TableName;
result.TableDescription = sugarTable.TableDescription;
}
if (this.Context.Context.CurrentConnectionConfig.ConfigureExternalServices != null && this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService != null) {
this.Context.CurrentConnectionConfig.ConfigureExternalServices.EntityNameService(type,result);

View File

@ -12,6 +12,7 @@ namespace SqlSugar
private string _DbTableName;
public string EntityName { get; set; }
public string DbTableName { get { return _DbTableName == null ? EntityName : _DbTableName; } set { _DbTableName = value; } }
public string TableDescription { get; set; }
public Type Type { get; set; }
public List<EntityColumnInfo> Columns { get; set; }
}

View File

@ -10,9 +10,15 @@ namespace SqlSugar
public class SugarTable : Attribute {
private SugarTable() { }
public string TableName { get; set; }
public string TableDescription { get; set; }
public SugarTable(string tableName) {
this.TableName = tableName;
}
public SugarTable(string tableName,string tableDescription)
{
this.TableName = tableName;
this.TableDescription = tableName;
}
}
[AttributeUsage(AttributeTargets.Property , Inherited = true)]
public class SugarColumn : Attribute

View File

@ -37,6 +37,7 @@ namespace SqlSugar
bool BackupTable(string oldTableName, string newTableName, int maxBackupDataRows = int.MaxValue);
bool DropColumn(string tableName,string columnName);
bool RenameColumn(string tableName, string oldColumnName, string newColumnName);
bool AddRemark(EntityInfo entity);
bool AddColumnRemark(string columnName,string tableName,string description);
bool DeleteColumnRemark(string columnName, string tableName);
bool IsAnyColumnRemark(string columnName, string tableName);