2012-10-04 5 views
4

Possible en double:
Exclude a field/property from the database with Entity Framework 4 & Code-FirstEF Code de la première colonne exclut

J'utilise EF 4 code premier.

Existe-t-il une méthode pour exclure la création d'une colonne dans la base de données?

Par exemple, je souhaite exclure la colonne Zip à créer.

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; } 

Merci.

+0

Voir cette annonce: http://stackoverflow.com/questions/1707663/exclude-a-field-property -à partir de la base de données avec l'entité-framework-4-code-first – TGlatzer

Répondre

7

Vous pouvez ajouter un attribut [NotMapped] à la propriété que vous souhaitez exclure de la base de données:

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; } 
Questions connexes