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

  • Home
  • SEARCH
  • 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 6101679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:38+00:00 2026-05-23T13:31:38+00:00

I have an Entity Framework POCO class that is generated by a T4 Template.

  • 0

I have an Entity Framework POCO class that is generated by a T4 Template.

I am planning to use the generated class as my data contract. However, it has a few properties that don’t need to be in the contract. For example I have a property called AddressId. It is the foreign key to the address table. Since the actual address is attached to the object I don’t want the AddressId to be visible to the client.

I could modify the T4 template, but I would rather not.

I saw this post that showed how to use ‘MetadataType’ to add attributes to existing properties in partial classes. This is the example that they gave:

[MetadataType(typeof(Dinner_Validation))] 
public partial class Dinner {} 

public class Dinner_Validation 
{ 
   [Required] 
   public string Title { get; set; } 
}

But I tried that for my class (using [IgnoreDataMember]) and it does not work (the AddressId is still shown).

How can I hide this one property without having to make a whole new class to copy all my data into?

  • 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-23T13:31:38+00:00Added an answer on May 23, 2026 at 1:31 pm

    MetadataType works only with data annotations. It doesn’t work with serialization attributes. Serialization attributes must be placed directly on properties in entity so if you want to use T4 template for class generation you must add logic for creating these attributes directly to template.

    Edit:

    If you want to build logic for generating special attributes you need somehow to tell T4 template which properties should be marked with the attribute. You can either hardcode such information into T4 template or you can put that information into EDMX file. EDMX file supports custom data elements in its XML structure. These custom XML elements can be latter used in T4 template for some additional logic. The only problem is that designer doesn’t have support for that – you must add custom elements directly into EDMX opened as XML.

    This whole is called Structural annotations. Some example with reverse processing (modifying database generation) can be found in my other answer (also check MSDN topic linked in the question). There is also whole extension project which perhaps allows adding new extensions together with designer support. I think you can also read about these customizations in Entity Framework 4 in Action book.

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

Sidebar

Related Questions

I have an assembly generated using POCO template using Entity Framework (e.g. Company.Models.dll).Besides generated
I have an entity class that has a property with an underlying db column
I have the following Entity Framework POCO classes: public class Customer { public int
I am using Entity Framework POCO to generate some self-tracked data objects, and I
For my ASP.NET MVC 2 application I use Entity Framework 1.0 as my data
I have a complete separation of my Entity Framework objects and my POCO objects,
I have a database table and a corresponding entity class (POCO with change tracking
Entity Framework 4, POCO objects and ASP.Net MVC2. I have a many to many
I have a website that has the views generated directly from objects created by
I have a WCF service with an Entity Framework 4 model, using POCO classes

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.