5

可能重复:
使用实体框架 4 和代码优先从数据库中排除字段/属性

我使用的是 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; }

谢谢你。

4

1 回答 1

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; }
于 2012-10-04T09:59:19.620 回答