上兩篇我們已經有了一個XML,並且根據這個XML生成了數據庫,這次我們來看一下如何從這個XML得到 初步的實體類。還是那個XML:
1: <?xml version="1.0" encoding="utf-8" ?> 2: <Entities xmlns="http://it.ouc.edu.cn/EntityDescription/V2"> 3: <Entity title="日志" name="Blog" module="Blogs"> 4: <Item title="標題" name="Title" type="text" require="true"/> 5: <Item title="內容" name="Content" type="longtext" require="false"/> 6: <Item title="所屬分類" name="BlogClass" type="entity" entityName="BlogClass" require="false"/> 7: <Item title="創建時間" name="CreateDateTime" type="datetime" require="true"/> 8: <Item title="更新時間" name="UpdateDateTime" type="datetime" require="true"/> 9: </Entity> 10: <Entity title="日志分類" name="BlogClass" module="Blogs"> 11: <Item title="名稱" name="Name" type="text" require="true"/> 12: <Item title="描述" name="Description" type="text" require="false"/> 13: </Entity> 14: </Entities>
修改上用於生成數據庫腳本的那個單元測試,加入以下代碼:
1: /// <summary> 2: /// 構造實體代碼 3: /// </summary> 4: [TestMethod, Description("構造實體代碼")] 5: public void Util_CreateEntityCodes() 6: { 7: var entities = getEntities(); 8: var baseSpace = "DongBlog.Business"; 9: var usingNameSpace = new string[] { "DongBlog.Common" }; 10: var path = Gobal.SolutionPath + @"/DongBlog.Business"; 11: 12: new LinqEntityCodeGenerater().Generate(path, baseSpace, entities, usingNameSpace, false); 13: }