Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Code First exclude column [duplicate]

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.

like image 521
Alvin Avatar asked Oct 04 '12 09:10

Alvin


1 Answers

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; }
like image 76
Kristof Claes Avatar answered Oct 13 '22 01:10

Kristof Claes