[英]MVC T4 MvcTextTemplateHost and Customized “Controller” T4 Template
I am creating my own custom T4 Template that integrates with an ADO.NET Entity Framework Model (.edmx file) included in my MVC Web Application. 我正在创建自己的自定义T4模板,该模板与我的MVC Web应用程序中包含的ADO.NET实体框架模型(.edmx文件)集成。
Please take a brief look at the following two URLs. 请简要了解以下两个网址。
Use the T4 engine to generate the MVC Controller class with Action methods based on the ADO.NET Entity Framework Model's Primary Key(s). 使用T4引擎使用基于ADO.NET实体框架模型的主键的Action方法生成MVC Controller类。
Based on the Controller name (eg "ProductController") , I want to retrieve the [System.Type] information of the "Product" class from the ADO.NET Entity Framework model. 基于Controller名称(例如“ProductController”) ,我想从ADO.NET Entity Framework模型中检索“Product”类的[System.Type]信息。 I want to be able to retrieve System.Type information the same way as the MVC View T4 files (eg Edit.tt) as below.
我希望能够以与MVC View T4文件(例如Edit.tt)相同的方式检索System.Type信息,如下所示。
MvcTextTemplateHost mvcHost = (MvcTextTemplateHost) (Host);
Type type = mvcHost.ViewDataType;
I want to create the Controller method code-generation to read Primary Key information and etc from the ADO.NET Entity Framework Class via Reflection 我想创建Controller方法代码生成,以通过Reflection从ADO.NET实体框架类中读取主键信息等
and 和
generate basic CRUD operations and method signatures for EDIT, DETAILS, ADD operations etc... 为EDIT,DETAILS,ADD操作等生成基本的CRUD操作和方法签名...
However, as you can see from Quick Start Guide for ASP.NET MVC Developers article, I cannot retrieve [System.Type] for Controller T4 Template because the MvcTextTemplateHost class exposes only ViewDataType property for creating MVC Views. 但是,正如您可以从ASP.NET MVC开发人员快速入门指南中看到的那样,我无法检索Controller T4模板的[System.Type] ,因为MvcTextTemplateHost类仅公开用于创建MVC视图的ViewDataType属性。
My attempt to retrieve the [System.Type] by the following technique is NOT working because the modelType is being returned as null meaning it can't find the type. 我尝试通过以下技术检索[System.Type]是不行的,因为modelType被返回为null意味着它找不到类型。
Type modelType = Type.GetType(modelFullyQualifiedName, false, true);
I am assuming that this happens because the Entity Framework Model is included as part of my MVC Web Project and not included as part of a compiled .DLL library assembly. 我假设这是因为实体框架模型作为我的MVC Web项目的一部分包含在内, 而不是作为已编译的.DLL库程序集的一部分包含在内。
I would really appreciate if anyone can help me on this topic as this will allow me to generate 75% of the code for MVC Controller Action Methods for ADD,EDIT,DETAILS, etc.. and basic CRUD operation code. 我真的很感激,如果有人可以帮助我这个主题,因为这将允许我为ADD,EDIT,DETAILS等MVC控制器操作方法生成75%的代码和基本的CRUD操作代码。
You can use Reflector to decompile source code of MvcTextTemplateHost from C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\Microsoft.VisualStudio.Web.Extensions.dll assembly. 您可以使用Reflector从C:\\ Program Files(x86)\\ Microsoft Visual Studio 9.0 \\ Common7 \\ IDE \\ Microsoft.VisualStudio.Web.Extensions.dll程序集中反编译MvcTextTemplateHost的源代码。
Yes, you can load type metadata from a Visual Studio using CodeModel . 是的,您可以使用CodeModel从Visual Studio加载类型元数据。 However, you may be better off reading it from the edmx file directly.
但是,您最好直接从edmx文件中读取它。 Either way, this is a substantial task.
无论哪种方式,这都是一项重大任务。 There may be a usable example of how to do this in the form of EF T4 template in VS 2010.
在VS 2010中,可能有一个如何以EF T4模板的形式执行此操作的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.