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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:36:35+00:00 2026-06-03T00:36:35+00:00

My understanding is that the [NotMapped] attribute is not available until EF 5 which

  • 0

My understanding is that the [NotMapped] attribute is not available until EF 5 which is currently in CTP so we cannot use it in production.

How can I mark properties in EF 4.1 to be ignored?

UPDATE: I noticed something else strange. I got the [NotMapped] attribute to work but for some reason, EF 4.1 still creates a column named Disposed in the database even though the public bool Disposed { get; private set; } is marked with [NotMapped]. The class implements IDisposeable of course but I don’t see how that should matter. Any thoughts?

  • 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-06-03T00:36:38+00:00Added an answer on June 3, 2026 at 12:36 am

    You can use the NotMapped attribute data annotation to instruct Code-First to exclude a particular property

    public class Customer
    {
        public int CustomerID { set; get; }
        public string FirstName { set; get; } 
        public string LastName{ set; get; } 
        [NotMapped]
        public int Age { set; get; }
    }
    

    [NotMapped] attribute is included in the System.ComponentModel.DataAnnotations namespace.

    You can alternatively do this with Fluent API overriding OnModelCreating function in your DBContext class:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
       modelBuilder.Entity<Customer>().Ignore(t => t.LastName);
       base.OnModelCreating(modelBuilder);
    }
    

    http://msdn.microsoft.com/en-us/library/hh295847(v=vs.103).aspx

    The version I checked is EF 4.3, which is the latest stable version available when you use NuGet.


    Edit : SEP 2017

    Asp.NET Core(2.0)

    Data annotation

    If you are using asp.net core (2.0 at the time of this writing), The [NotMapped] attribute can be used on the property level.

    public class Customer
    {
        public int Id { set; get; }
        public string FirstName { set; get; } 
        public string LastName { set; get; } 
        [NotMapped]
        public int FullName { set; get; }
    }
    

    Fluent API

    public class SchoolContext : DbContext
    {
        public SchoolContext(DbContextOptions<SchoolContext> options) : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Customer>().Ignore(t => t.FullName);
            base.OnModelCreating(modelBuilder);
        }
        public DbSet<Customer> Customers { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding is that both JAAS and SQL Server can be configured to use
It's my understanding that nulls are not indexable in DB2, so assuming we have
It's my understanding that common wisdom says to only use exceptions for truly exceptional
It is my understanding that I can test that a method call will occur
It is to my understanding that one should use a forward-class declaration in the
It is my understanding that the java.regex package does not have support for named
It's my understanding that the Java compiler produces byte code, not object code. First
It is my understanding that it is not possible to have an optional parameter
Am I correct in my understanding that I can only pass-through one custom variable
It's my understanding that the constructor for a controller is not called during each

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.