/// <summary>写入</summary> /// <param name="writer"></param> void IXmlSerializable.WriteXml(XmlWriter writer) { ModelHelper.WriteXml(this, writer); }
/// <summary>读取</summary> /// <param name="reader"></param> void IXmlSerializable.ReadXml(XmlReader reader) { ModelHelper.ReadXml(this, reader); }
/// <summary>导出模型</summary> /// <param name="tables"></param> /// <returns></returns> public static String Export(IEnumerable <IDataTable> tables) { return(ModelHelper.ToXml(tables)); }
/// <summary>导出模型</summary> /// <param name="tables"></param> /// <returns></returns> public static String Export(IEnumerable <IDataTable> tables) => ModelHelper.ToXml(tables);
/// <summary>检查表说明和索引</summary> /// <param name="entitytable"></param> /// <param name="dbtable"></param> /// <param name="mode"></param> /// <returns></returns> protected virtual String CheckTableDescriptionAndIndex(IDataTable entitytable, IDataTable dbtable, Migration mode) { var onlySql = mode <= Migration.ReadOnly; var noDelete = mode < Migration.Full; var sb = new StringBuilder(); #region 表说明 if (entitytable.Description + "" != dbtable.Description + "") { //// 先删除旧注释 //if (!String.IsNullOrEmpty(dbtable.Description)) PerformSchema(sb, onlySql, DDLSchema.DropTableDescription, dbtable); // 加上新注释 if (!String.IsNullOrEmpty(entitytable.Description)) { PerformSchema(sb, onlySql, DDLSchema.AddTableDescription, entitytable); } } #endregion #region 除索引 var dbdis = dbtable.Indexes; if (dbdis != null) { foreach (var item in dbdis.ToArray()) { // 计算的索引不需要删除 //if (item.Computed) continue; // 主键的索引不能删 if (item.PrimaryKey) { continue; } var di = ModelHelper.GetIndex(entitytable, item.Columns); if (di != null && di.Unique == item.Unique) { continue; } PerformSchema(sb, noDelete, DDLSchema.DropIndex, item); dbdis.Remove(item); } } #endregion #region 新增索引 var edis = entitytable.Indexes; if (edis != null) { foreach (var item in edis.ToArray()) { if (item.PrimaryKey) { continue; } var di = ModelHelper.GetIndex(dbtable, item.Columns); // 计算出来的索引,也表示没有,需要创建 if (di != null && di.Unique == item.Unique) { continue; } //// 如果这个索引的唯一字段是主键,则无需建立索引 //if (item.Columns.Length == 1 && entitytable.GetColumn(item.Columns[0]).PrimaryKey) continue; // 如果索引全部就是主键,无需创建索引 if (entitytable.GetColumns(item.Columns).All(e => e.PrimaryKey)) { continue; } PerformSchema(sb, onlySql, DDLSchema.CreateIndex, item); if (di == null) { edis.Add(item.Clone(dbtable)); } //else // di.Computed = false; } } #endregion if (!onlySql) { return(null); } return(sb.ToString()); }