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 6927525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:04:00+00:00 2026-05-27T11:04:00+00:00

I’ve customized the EF T4 code generation following these steps . All good, but

  • 0

I’ve customized the EF T4 code generation following these steps. All good, but It seems that the EF Designer view, where you see the tables as “entities” and the mapping between the properties and the columns in the table. My code shows the changes I make in the T4 template but the designer doesn’t. Also, it doesn’t update the code if I add a new table to the designer. Is there something I’m missing?

Edit:
The customization I’ve done so far is adding a custom property to each of the generated entities. Below is the T4 code:

region.Begin(GetResourceString("Template_RegionPrimitiveProperties"));

    WriteLine("");
    Write("\t");
    WriteLine("[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]");
    Write("\t");
    WriteLine("[DataMemberAttribute()]");
    Write("\t");
    WriteLine("public Guid OriginalId { get; set; }");

    foreach (EdmProperty property in entity.Properties.Where(p => p.DeclaringType == entity && p.TypeUsage.EdmType is PrimitiveType))

All the “Write” and “WriteLine” calls are my own. I know is not the best way to do it but I’m still getting the hang of T4. If the way I’m writing this is the problem, please point me to the right direction on how I should add this custom property.

  • 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-27T11:04:01+00:00Added an answer on May 27, 2026 at 11:04 am

    The designer displays off of the edmx XML, not the C# code it generates. So you may be modifying the generated code…but that doesn’t affect what the designer displays.

    Further…if you try to rewrite the edmx XML itself with your customization so that it does display in the designer, you’ve got to make sure you map your new property correctly in the csdl, msl, and ssdl, or the edmx won’t validate.

    BTW, it’s not that terrible to modify the edmx xml using your T4 template either. Here’s an example I wrote to automatically generate and update the edmx with a TPH (table per heirarchy) SSDL and MSL any time the edmx is saved (using some templates from the Database Generation Power Pack). This lives in my entity generation T4 template, which gets called whenever the edmx is saved.

    <#@ assembly name="System.Core" #>
    <#@ assembly name="System.Xml" #>
    <#@ assembly name="System.Xml.Linq" #>
    <#@ assembly name="System.Data" #>
    <#@ assembly name="System.Data.Entity" #>
    <#@ assembly name="System.Data.Entity.Design" #>
    <#@ assembly name="$(DevEnvDir)Microsoft.Data.Entity.Design.DatabaseGeneration.dll"#>
    <#@ assembly name="$(ProjectDir)..\..\Dependencies\Microsoft.Data.Entity.Design.DatabaseGenerationToolkit.dll"#>
    <#@ import namespace="System.Linq" #>
    <#@ import namespace="System.Xml" #>
    <#@ import namespace="System.Text" #>
    <#@ import namespace="System.Collections.Generic" #>
    <#@ import namespace="System.Data" #>
    <#@ import namespace="System.Data.Common" #>
    <#@ import namespace="System.Data.Entity.Design" #>
    <#@ import namespace="System.Data.Metadata.Edm" #>
    <#@ import namespace="System.Diagnostics" #>
    <#@ import namespace="System.Globalization" #>
    <#@ import namespace="Microsoft.Data.Entity.Design.DatabaseGeneration" #>
    <#@ import namespace="Microsoft.Data.Entity.Design.DatabaseGenerationToolkit" #>
    <#@ import namespace="System.Runtime.Remoting.Messaging" #>
    <#@ import namespace="System.Text.RegularExpressions" #>
    <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
    <#@ import namespace="System.IO" #>
    <#@ template language="C#" debug="true" hostspecific="true" #>
    <#@ include file="GenerateTSQL.Utility.ttinclude"#>
    <#@ include file="GenerateEDM.Utility.ttinclude"#>
    <#@ output extension = ".xml" #>
    <#
    string inputFile = @"Model.edmx";
    
    inputFile = Host.ResolvePath(inputFile);
    
    var ssdlTransformPath = Host.ResolvePath(@"GenerateSSDL_TPH.tt");
    var mslTransformPath = Host.ResolvePath(@"GenerateMSL_TPH.tt");
    
    var document = new XmlDocument();
    document.PreserveWhitespace = true;
    
    document.Load(inputFile);
    var namespaceManager = new XmlNamespaceManager(document.NameTable);
    namespaceManager.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2008/10/edmx");
    namespaceManager.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl");
    
    var schema = "model";
    var schemaNode = document.SelectSingleNode("//edmx:DesignerProperty[@Name='DefaultDatabaseSchema']", namespaceManager);
    if (schemaNode != null) schema = schemaNode.Attributes["Value"].Value;
    
    var csdl = document.SelectSingleNode("//edmx:ConceptualModels", namespaceManager).InnerXml;
    
    CallContext.SetData(EdmConstants.csdlInputName, csdl);
    CallContext.SetData(EdmParameterBag.ParameterName.TargetVersion.ToString(), new Version("2.0.0.0"));
    CallContext.SetData(EdmParameterBag.ParameterName.ProviderInvariantName.ToString(), "System.Data.SqlClient");
    CallContext.SetData(EdmParameterBag.ParameterName.ProviderManifestToken.ToString(), "2005");
    CallContext.SetData(EdmParameterBag.ParameterName.DatabaseSchemaName.ToString(), schema);
    CallContext.SetData(EdmParameterBag.ParameterName.DatabaseName.ToString(), document.SelectSingleNode("//ssdl:EntityContainer", namespaceManager).Attributes["Name"].Value);
    CallContext.SetData(EdmParameterBag.ParameterName.EdmxPath.ToString(), inputFile);
    
    string ssdl = new Engine().ProcessTemplate(File.ReadAllText(ssdlTransformPath), Host);
    var ssdlNode = document.SelectSingleNode("//edmx:StorageModels", namespaceManager);
    ssdlNode.InnerXml = ssdl;
    
    CallContext.SetData(EdmConstants.existingSsdlInputName, ssdl);
    CallContext.SetData(EdmConstants.ssdlOutputName, ssdl);
    
    string msl = new Engine().ProcessTemplate(File.ReadAllText(mslTransformPath), Host);
    var mslNode = document.SelectSingleNode("//edmx:Mappings", namespaceManager);
    mslNode.InnerXml = msl;
    
    var isChanged = document.OuterXml != File.ReadAllText(inputFile);
    
    if (isChanged) 
    {
        document.Save(inputFile);
    }
    #>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.