/// <summary> /// 更新类信息 /// </summary> /// <param name="ctype"></param> /// <param name="project"></param> /// <param name="currentDiagram"></param> /// <returns></returns> public static EntityConfig GetEntityConfigByTable(ClrType ctype, ClassDesignerInfo desinfo) { EntityConfig entity = new EntityConfig(ctype, desinfo); //entity.DesignerInfo.SelectDocView = selectDocView; if (string.IsNullOrEmpty(entity.TableName)) { return(null); } DBInfo db = entity.DbInfo.CreateDBInfo(); List <string> selTab = new List <string>(); selTab.Add(entity.TableName); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selTab); if (lstGen.Count > 0) { DBTableInfo info = lstGen[0]; Dictionary <string, EntityParamField> dicParam = entity.GetParamMapField(); entity._dbParams = new List <EntityParam>(); foreach (EntityParam prm in info.Params) { string paramName = prm.ParamName; if (dicParam.ContainsKey(paramName)) { continue; } entity._dbParams.Add(prm); } Dictionary <string, EntityRelationItem> dicRelation = entity.GetRelationmMapField(); entity._dbRelations = new List <TableRelationAttribute>(); foreach (TableRelationAttribute tr in info.RelationItems) { string key = EntityFieldBase.ToPascalName(tr.TargetTable) + ":" + EntityFieldBase.ToPascalName(tr.SourceName) + ":" + EntityFieldBase.ToPascalName(tr.TargetName); if (dicRelation.ContainsKey(key)) { continue; } entity._dbRelations.Add(tr); } } return(entity); }
/// <summary> /// 添加映射信息 /// </summary> /// <param name="entity"></param> /// <param name="classNode"></param> private static void AppendRelationInfo(List <TableRelationAttribute> relationItems, XmlNode classNode) { XmlDocument doc = classNode.OwnerDocument; if (relationItems == null) { return; } foreach (TableRelationAttribute field in relationItems) { //EntityParamField field = kp.Value; XmlNode node = doc.CreateElement("relation"); classNode.AppendChild(node); XmlAttribute att = doc.CreateAttribute("FieldName");//字段名 att.InnerText = field.FieldName; node.Attributes.Append(att); att = doc.CreateAttribute("PropertyName");//对应的属性名名 att.InnerText = field.PropertyName; node.Attributes.Append(att); att = doc.CreateAttribute("SourceProperty");//数据库类型 att.InnerText = EntityFieldBase.ToPascalName(field.SourceName); node.Attributes.Append(att); att = doc.CreateAttribute("TargetProperty");//数据库类型长度 att.InnerText = EntityFieldBase.ToPascalName(field.TargetName); node.Attributes.Append(att); att = doc.CreateAttribute("IsToDB");//数据库类型长度 att.InnerText = field.IsToDB ? "1" : "0"; node.Attributes.Append(att); att = doc.CreateAttribute("IsParent");//数据库类型长度 att.InnerText = field.IsParent ? "1" : "0"; node.Attributes.Append(att); att = doc.CreateAttribute("Description");//属性注释 att.InnerText = field.Description; node.Attributes.Append(att); } }