5

Possible Duplicate:
Exclude a field/property from the database with Entity Framework 4 & Code-First

I am using EF 4 code-first.

Is there any method to exclude creating a column into the database?

For example I want to exclude the Zip column to be created.

public string Address { get; set; }
[StringLength(40)]
public string City { get; set; }
[StringLength(30)]
public string State { get; set; }
[StringLength(10)]
public string Zip { get; set; }

Thank you.

Community
  • 1
  • 1
Alvin
  • 8,219
  • 25
  • 96
  • 177
  • See this Post: http://stackoverflow.com/questions/1707663/exclude-a-field-property-from-the-database-with-entity-framework-4-code-first – TGlatzer Oct 04 '12 at 09:55

1 Answers1

9

You can add a [NotMapped] attribute to the property you want to exclude from the database:

public string Address { get; set; }

[StringLength(40)]
public string City { get; set; }

[StringLength(30)]
public string State { get; set; }

[StringLength(10)]
[NotMapped]
public string Zip { get; set; }
Kristof Claes
  • 10,797
  • 3
  • 30
  • 42