Search code examples
c#.net-4.5ef-database-first

How can I add a property to a database first Model that is not going to be part of the Database


I am trying to set up a database first project to handle the data access for a database that is common to several applications that use. The value of these properties will be set differently based on the method called, who is calling, etc. Is there any way to set a property that has a get and set method that EF will not try to map to a database field?


Solution

  • Use the [NotMapped] Attribute.

    public class MappedClass
    {
        public string MappedProperty { get; set; }
        [NotMapped]
        public string NotMappedProperty { get; set; }
    }
    

    Reference MSDN