- 8
- 0
- 约2.32万字
- 约 20页
- 2018-05-02 发布于贵州
- 举报
T4模板的使用第一步,打开vs2013,在DAL文件夹上右击,添加,新建项第二步,在弹出的页面中选择文本模板,然后修改文本的名称,之后点击添加第三步,最终的结果如下:第四步,做如下的修改#@ template language=C# debug=false hostspecific=true#//注释:模板的语言为C##@ include file=EF6.Utility.CS.ttinclude#//注释:引用EF6#@ output extension=.cs #//注释:最终生成的文件时cs格式的#const string inputFile = @..\WebApp.Models\DataEntity.edmx;//注释:找到数据库生成的模型,以后根据这个数据库中的表生成文件var textTransform = DynamicTextTransformation.Create(this);var code = new CodeGenerationTools(this);var ef = new MetadataTools(this);var typeMapper = new TypeMapper(code, ef, textTransform.Errors);varfileManager = EntityFrameworkTemplateFileManager.Create(this);var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);##WriteHeader(codeStringGenerator, fileManager);//使用foreach循环遍历ItemCollection.GetItemsEntityType集合foreach (var entity in typeMapper.GetItemsToGenerateEntityType(itemCollection)){fileManager.StartNewFile(entity.Name + Repository.cs);//注释:最终生成的文件的样子是数据库中的表名Repository.cs#using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WebApp.DAL{public class #=entity.Name#Repository : BaseRepositoryWebApp.Models.#=entity.Name# { }}#}fileManager.Process();##+public void WriteHeader(CodeStringGenerator codeStringGenerator, EntityFrameworkTemplateFileManager fileManager){fileManager.StartHeader();#//// auto-generated// #=CodeGenerationTools.GetResourceString(Template_GeneratedCodeCommentLine1)#//// #=CodeGenerationTools.GetResourceString(Template_GeneratedCodeCommentLine2)#// #=CodeGenerationTools.GetResourceString(Template_GeneratedCodeCommentLine3)#// /auto-generated//#=codeStringGenerator.UsingDirectives(inHeader: true)##+fileManager.EndBlock();}public void BeginNamespace(CodeGenerationTools code){var codeNamespace = code.VsNamespaceSuggestion();if (!String.IsNullOrEmpty(codeNamespace)) {#namespace #=code.EscapeNamespace(codeNamespace)#{#+PushIndent
您可能关注的文档
- 2017年银行初级职业资格考试《银行管理》模拟试题及答案(三)5.docx
- 2017年银行初级职业资格考试《银行管理》模拟试题及答案(一)5.docx
- 2017年银行初级职业资格考试《银行管理》模拟试题及答案(五)5.docx
- 2017届广东省东莞市高三上学期期末测试地理试卷4.docx
- 2017年高考地理一轮复习方略43.docx
- 2018中国茶道尔雅通识课答案(二)20.docx
- 2018中国银行春季校园招聘公告内容6.docx
- 2018中国银行春季校园招聘报考条件(参考)6.docx
- 2018届广州市调研考历史试卷21.docx
- 2018年北京电影学院管理学院电影制片管理考研招生人数总括30.docx
- 2025年北京市门头沟区中考一模英语试题.docx
- 2025年北京市门头沟区中考二模英语试题.docx
- 2025年北京市丰台区中考二模英语试题.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 解析卷.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 原卷.docx
- 2025年肩颈按摩仪行业社媒趋势数据分析.docx
- 2025年人身险行业信用回顾与2026年展望.docx
- 合同法买卖合同培训课件.ppt
- 2025年全球食物系统与SDG研究报告-食物供给、食者健康、生态平衡的整体治理.docx
- 2025下半年四川乐山市川投峨眉铁合金(集团)有限责任公司对考前自测高频考点模拟试题最新.docx
最近下载
- 制鞋技术之成型后段技术培训教材01.pdf VIP
- 磁共振温度图像重建方法、装置、设备、介质及程序产品.pdf VIP
- 金田JTE 388系列变频器使用手册.pdf
- 人教版(PEP)2026-2027学年四年级英语下册教学计划(及进度表).docx
- 东北师范大学2021-2022学年第1学期《线性代数》期末考试试卷(A卷)及标准答案.docx
- 新生儿科消防安全知识培训.pptx VIP
- 第五章+中国的地理差异+课件-2023-2024学年八年级地理下学期人教版.pptx VIP
- 第五章+中国的地理差异+第1课时+课件-2023-2024学年八年级地理下学期人教版.pptx VIP
- 【地理】中国的地理差异第1课时课件-2025-2026学年人教版地理八年级下册.pptx VIP
- 第五章+中国的地理差异+第1课时课件2022-2023学年人教版地理八年级下册.pptx VIP
原创力文档

文档评论(0)