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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:40:17+00:00 2026-05-25T16:40:17+00:00

I have a modified T4 template that builds classes from my edmx and its

  • 0

I have a modified T4 template that builds classes from my edmx and its working smoothly except for derived classes.

Product : BaseItem // works fine as do all top level classes

TranslatedProduct : Product : BaseItem  // dang

I’m confused about how and where I can conditionally set the T4 template to ignore : BaseItem in the case of a derived class – ie

TranslatedProduct : Product

For example:

<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#> : BaseItem

In my head i imagined it like –

if(code.Escape(entity.BaseType).Equals(string.empty)
{
   <#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#> : BaseItem
}
else
{
<#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial      class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
}

But I receive syntax errors so I’d like to see if anyone else has tried this and if I’m on the right path

  • 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-25T16:40:18+00:00Added an answer on May 25, 2026 at 4:40 pm

    The scripts you provided hard-code : BaseItem to always appear. This seems broken.

    The original code is:

    <#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#>
    

    This uses a class defined in:

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF.Utility.CS.ttinclude

    The portions of the script between <#= #> tags are just C# expressions, and the strings returned by those expressions are inserted inline.

    The code.Escape method will return either the type name (as a string) or an empty string.

    The code.StringBefore will append the first string (" : ") before the second string (the base type name), but only if the second string isn’t null or empty.

    To do what you’re trying to accomplish, you can use the same trick they use, but in reverse. Unfortunately you can’t use their existing class, because they don’t have some sort of AppendIfNotDefined method. So we’ll just use a more complicated expression.

    Instead of:

    code.StringBefore(" : ", code.Escape(entity.BaseType))
    

    We’ll write:

    code.StringBefore(" : ",
        string.IsNullOrEmpty(code.Escape(entity.BaseType))
            ? "BaseItem"
            : code.Escape(entity.BaseType)
        )
    

    Here’s the whole line, all crammed together:

    <#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", string.IsNullOrEmpty(code.Escape(entity.BaseType)) ? "BaseItem" : code.Escape(entity.BaseType))#>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a T4 template that generates classes from an xml file. How can
I have modified a working Windows service that had always been starting beforehand. After
I have some template classes I've written that are dependencies for several other classes
Background I have a custom control that inherits from a TreeView and is modified
I have a dataset that I have modified into an xml document and then
I create a working repository in HG. And I have modified some files. How
I have a product consisting of several plugins that I want to build. The
I have developed a kind of brochure website template that I base most of
I'm maintaining the Perl Beginners' Site and used a modified template from Open Source
I have an application set up so that I can adjust its skin at

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.