Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 273159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:24:53+00:00 2026-05-12T00:24:53+00:00

I am creating my own custom T4 Template that integrates with an ADO.NET Entity

  • 0

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.

For Reference

Please take a brief look at the following two URLs.

  1. Scott Hanselman – “T4 Code Generation Visual Studio Best Kept Secret“
  2. Visual Web Developer Team Blog – Quick Start Guide for ASP.NET MVC Developers

Short Description of What I am trying to Achieve

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).

What I Have Right Now

  1. MVC T4 Template files (e.g., Controller.tt, Create.tt, etc…) have been included as part of my MVC Web Project.
  2. I have an ADO.NET Entity Framework MyModel.edmx file in the “Models” folder.

Based on the Controller name (e.g. “ProductController”), I want to retrieve the [System.Type] information of the “Product” class from the ADO.NET Entity Framework model.
I want to be able to retrieve System.Type information the same way as the MVC View T4 files (e.g. Edit.tt) as below.

MvcTextTemplateHost mvcHost = (MvcTextTemplateHost) (Host);
Type type = mvcHost.ViewDataType;

Final Goal

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
and
generate basic CRUD operations and method signatures for EDIT, DETAILS, ADD operations etc…

Where I am Stuck

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.

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.

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.

Some Things that Will Help Me Find the Solution

  1. Where do I find the Source Code for the MvcTextTemplateHost class? If I can find at least the DLL file, I can probably look at how the code loads the Type information entered in the Visual Studio “Add View” dialog window.
  2. Is there a way to dynamically retrieve System.Type information of a Class included in the Visual Studio project from my T4 Template through the Visual Studio IDE API?

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:24:54+00:00Added an answer on May 12, 2026 at 12:24 am
    1. 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.

    2. Yes, you can load type metadata from a Visual Studio using CodeModel. However, you may be better off reading it from the edmx file directly. 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating my own JavaScript Array-like object and I have methods that call closures.
I am considering creating my own website using Java and am trying to decide
I'm creating my own dictionary and I am having trouble implementing the TryGetValue function.
I am currently in the process of creating my own blog and I have
I am creating a user control in C# and I am adding my own
I'm getting ORA-01031: insufficient privileges when creating a package my own schema. Shouldn't I
Is there a generic way, without creating and managing your own CLR host, to
I have a problem with creating my own subclass of NSData , which I
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.