2012-10-04 156 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; }