EF Code First排除列

Alv*_*vin 5 c# entity-framework ef-code-first

可能重复:
使用Entity Framework 4和Code-First从数据库中排除字段/属性

我正在使用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; }
Run Code Online (Sandbox Code Playgroud)

谢谢.

Kri*_*aes 9

您可以[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; }
Run Code Online (Sandbox Code Playgroud)