2012-10-04 153 views
4

可能重複:
Exclude a field/property from the database with Entity Framework 4 & Code-FirstEF代碼首先排除列

我使用EF 4代碼優先。

有什麼方法可以排除在數據庫中創建列嗎?

例如,我想排除要創建的Zip列。

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

謝謝。

+0

看到這個帖子:http://stackoverflow.com/questions/1707663/exclude-a-field-property - 從最數據庫與實體框架-4-代碼優先 – TGlatzer

回答

7

您可以將[NotMapped]屬性添加到您希望從數據庫中排除的屬性:

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