ef6의 실체 모델 edmx 파일에 필드 설명을 추가합니다
                                            
 9528 단어  C#/.NET/VS/Linq
                    
//주석 섹션 코드 생성
=0;i--) { if(TableName[i]>='A'&& TableName[i]<='Z') { TableName=TableName.Substring(0,i)+TableName.Substring(i,1).ToLower()+TableName.Substring(i+1); break; } } */ string primaryname=Table.PrimaryKey.MemberColumns[0].Name; string primarytype= CSharpAlias[Table.PrimaryKey.MemberColumns[0].SystemType.FullName]; string autoname="",autotype=""; foreach(ColumnSchema cs in Table.Columns) { if( ((bool)cs.ExtendedProperties["CS_IsIdentity"].Value) == true) { autoname=cs.Name; autotype=CSharpAlias[cs.SystemType.FullName]; break; } } Listfkeys=new List ();// foreach(var item in Table.ForeignKeys) { fkeys.Add(item.ForeignKeyMemberColumns[0].Name); //Response.Write(item.ForeignKeyMemberColumns[0].Name+"--"+item.PrimaryKey.Table.Name+" 
"); } TableSchemaCollection tables=new TableSchemaCollection();; if(IsAll !=true) { tables.Add(Table); } else { tables=this.SourceDatabase.Tables; } %>0) precision=" Precision=\""+col.Scale+"\""; //col.Precision %> > 
//生成文件到硬上
    //        
     private string Directory = String.Empty;
    [Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]   
    [Optional, NotChecked]
    [DefaultValue("")]
    public string OutputDirectory 
    { 
        get
        {
            return Directory;
        }
        set
        {
            if (value.EndsWith("\\")) value = value.Substring(0, value.Length -1);
            Directory = value;
        } 
    }
    public string GetSubspace(string tableName)
    {
        
        for(int i=tableName.Length-1;i>=0;i--)
        {
            if(tableName[i]>='A'&& tableName[i]<='Z')
            {
                tableName=tableName.Substring(0,i)+tableName.Substring(i,1).ToLower()+tableName.Substring(i+1);
                break;
            }
        }
        return tableName;
    }
        //    Entity 
    private void GenerateEntityClasses()
    {
        CodeTemplate edmx_sumaryTemplate =new edmx_sumary();
        /*
        ////    BaseDAL   
        string basedalDirectory = OutputDirectory +"\\DAL\\BaseDAL.cs";
        basedalTemplate.SetProperty("NM",MyNameSpace);//    
        basedalTemplate.RenderToFile(basedalDirectory,true);//    
        Debug.WriteLine(basedalDirectory +"     .");
        */
        
            Response.WriteLine("……………………    ……………………");
            string edmx_sumaryDirectory = OutputDirectory +"\\edmx_sumary.xml";
            
            //  Service  
            edmx_sumaryTemplate.SetProperty("SourceDatabase",SourceDatabase);
            edmx_sumaryTemplate.SetProperty("Table",Table);
            edmx_sumaryTemplate.SetProperty("IsAll",IsAll);
            edmx_sumaryTemplate.RenderToFile(edmx_sumaryDirectory,true);//    
            Response.WriteLine(edmx_sumaryDirectory +"     .");
            
            Response.WriteLine("……………………     ……………………");
    }
 
c# 새 콘솔 응용 프로그램으로 eDMx의 필드에 주석을 달습니다.
    class Program
    {
        static void Main(string[] args)
        {
            Work wk = new Work();
            wk.DoWork();
            Console.ReadKey();
        }
    }
    public class Work
    {
//        exe      
        public string InXmlPath = "edmx_sumary.xml";//code smith       
        public string OutXmlPath = "SysEntities.edmx";
        public void DoWork()
        {
            string InFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, InXmlPath);
            string OutFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, OutXmlPath);
            XmlDocument inputDoc = new XmlDocument();
            XmlDocument outputDoc = new XmlDocument();
            inputDoc.Load(InFile);
            outputDoc.Load(OutFile);
            XmlNodeList inList = inputDoc.SelectNodes("/Schema/EntityType");
            if (inList == null || inList.Count == 0) return;
            XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(outputDoc.NameTable);
            xmlnsManager.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx");
            xmlnsManager.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation");
            xmlnsManager.AddNamespace("customannotation", "http://schemas.microsoft.com/ado/2009/02/edm/customannotation");
            //  "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edmx:Schema/edmx:EntityType"
            XmlNode outSchemaNode = outputDoc.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels", xmlnsManager).ChildNodes[0];
            foreach (XmlNode inNode in inList)//       
            {
                if (inNode.NodeType == XmlNodeType.Comment) continue;
                XmlElement inElement = (XmlElement)inNode;
                string tableName = inElement.GetAttribute("Name");
                Console.Write(tableName + "  ;  ");
                Console.WriteLine();
                XmlElement outElement = null;
                foreach (XmlNode outNodetemp in outSchemaNode.ChildNodes)//                     
                {
                    if (outNodetemp.NodeType == XmlNodeType.Comment || outNodetemp.Name == "EntityContainer" || outNodetemp.Name == "Association") continue;
                    XmlElement xe_edmx = (XmlElement)outNodetemp;
                    string o_tableName = xe_edmx.GetAttribute("Name");
                    if (o_tableName == tableName)
                    {
                        outElement = xe_edmx; break;
                    }
                }
                if (outElement == null) continue;
                Console.WriteLine("edmx:" + outElement.GetAttribute("Name"));
                foreach (XmlNode field in outElement.ChildNodes)
                {
                    if (field.NodeType == XmlNodeType.Comment) continue;
                    XmlElement field_element = (XmlElement)field;
                    //if (field_element.NodeType == XmlNodeType.Comment || field_element.Name == "NavigationProperty" || field_element.Name == "Key") continue;
                    if (field_element.Name == "Documentation") outElement.RemoveChild(field);//            
                }
                //outputDoc.Save(OutFile + "new.edmx"); return;
                foreach (XmlNode field in inElement.ChildNodes)//         
                {
                    if (field.NodeType == XmlNodeType.Comment || field.Name=="Key") continue;
                    XmlElement field_element = (XmlElement)field;
                    string fieldName = field_element.GetAttribute("Name");
                    if (field_element.Name == "Documentation")
                    {
                        XmlElement temp = outputDoc.CreateElement("Documentation", "http://schemas.microsoft.com/ado/2013/11/edm/Property");
                        XmlElement tempc = outputDoc.CreateElement("Summary");
                        tempc.InnerText = field.InnerText;
                        temp.AppendChild(tempc);
                        Console.WriteLine("val:" + temp.Value);
                        outElement.AppendChild(temp);
                    }
                    else if (field_element.Name == "Property")
                    {
                        foreach (XmlNode outfield in outElement.ChildNodes)
                        {
                            if (outfield.NodeType == XmlNodeType.Comment) continue;
                            XmlElement outfield_element = (XmlElement)outfield;
                            if (outfield_element.GetAttribute("Name") == fieldName)
                            {
                                outfield.InnerXml = field.InnerXml;//                   
                                break;
                            }
                        }
                    }
                }
            }
            outputDoc.Save(OutFile + "new.edmx");//      ,         ,        。
        }
    }
tt모드에서도 코드를 써서 eDMx에서 주석을 읽어야 합니다. 현재 주석은 eDMx 파일에 있습니다. 수첩으로 열어 볼 수 있습니다.
tt가 eDMx의 주석을 읽는 것에 관해서는 인터넷 코드가 매우 많아서 모두 가능하다.