/// <summary> /// 查找当前站点中的所有表规则 /// </summary> /// <returns></returns> public static List <TableRule> GetAllTables() { List <TableRule> allRuleList = new List <TableRule>(); #region 读取本项目 string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "/DataRules.xml"; //获取本项目节点的数据规则 if (System.IO.File.Exists(xmlPath)) //如果存在,则读取规则文件 { XElement ruleRoot = XElement.Load(xmlPath); foreach (var tableElement in ruleRoot.Elements("Table")) { TableRule tempRule = new TableRule(tableElement); allRuleList.Add(tempRule); } } #endregion #region 读取插件dll List <Assembly> distinctAssemblies = AssemblyHelper.GetPluginAssemblies(); foreach (Assembly plugin in distinctAssemblies) //遍历插件 { AssemblyTitleAttribute titleAttr = (AssemblyTitleAttribute)(plugin.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]); string xmlUrl = titleAttr.Title + ".DataRules.xml"; Stream xmlStream = plugin.GetManifestResourceStream(xmlUrl); if (xmlStream != null) { StreamReader xmlReader = new StreamReader(xmlStream); string xmlContent = xmlReader.ReadToEnd(); XElement ruleRoot = XElement.Parse(xmlContent); foreach (var tableElement in ruleRoot.Elements("Table")) { TableRule tempRule = new TableRule(tableElement); allRuleList.Add(tempRule); } } } #endregion return(allRuleList); }
/// <summary> /// 获取当前表的所有子表,即有外键到到当前表的表 /// </summary> /// <param name="tbName"></param> /// <returns></returns> public static List <TableRule> GetAllForeignTables(string tbName) { List <TableRule> foreignTables = new List <TableRule>(); //与当前要删除表有外键关联的表 foreach (var tempTable in TableRule.GetAllTables()) //循环所有表结构 { //判断表内字段,有存在SourceTable为当前要删除记录的表的,则记录 if (tempTable.ColumnRules.Where(t => t.SourceTable == tbName).Count() > 0) { foreignTables.Add(tempTable); } } return(foreignTables); }