借鉴 EF 生成实体的方法,
1 <#@ template language="C#" debug="false" hostspecific="true"#>
2 <#@ include file="EF.Utility.CS.ttinclude"#><#@
3 output extension=".cs"#>
4
5 <#
6
7 CodeGenerationTools code = new CodeGenerationTools(this);
8 MetadataLoader loader = new MetadataLoader(this);
9 CodeRegion region = new CodeRegion(this, 1);
10 MetadataTools ef = new MetadataTools(this);
11
12 string inputFile = @"E:\YC96\9.MVC4\2017.11.13内容\Code\Direct.YC96.Models\MyFrameDBModels.edmx";
13
14 EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
15 string namespaceName = code.VsNamespaceSuggestion();
16
17 EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this);
18
19 #>
20 <#
21 // Emit Entity Types
22 foreach (EntityType entity in ItemCollection.GetItems().OrderBy(e => e.Name))
23 {
24 fileManager.StartNewFile("文件名.cs");// 创建文件 名
25 #>
26 //类文件代码
27 using System;
28 using System.Collections.Generic;
29 using System.Linq;
30 using System.Linq.Expressions;
31 using System.Text;
32 using System.Threading.Tasks;
33
34 namespace 命名空间
35 {
36
37 //BeginNamespace(namespaceName, code);
38
39 public interface I<#=entity.Name#>DAL:IBaseDAL<<#=entity.Name#>>
40 {
41
42 }
43
44 }
45 <#
46
47
48 }
49 fileManager.Process();// 调用生成文件的 方法
50 #>
51
52
53
54