EF Code First如何排除列

5

可能是重复问题:
如何在使用Entity Framework 4和Code-First时将字段/属性从数据库中排除

我正在使用EF 4 Code-First。

有没有任何方法可以排除在数据库中创建一个列?

例如,我想要排除 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; }

谢谢你。


请查看此帖子:https://dev59.com/JHI-5IYBdhLWcg3wu7BU - TGlatzer
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; }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接