【问题标题】:EF Code First exclude column [duplicate]EF Code First 排除列[重复]
【发布时间】:2012-09-25 08:02:08
【问题描述】:

可能重复:
Exclude a field/property from the database with 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; }

谢谢。

【问题讨论】:

标签: c# entity-framework ef-code-first


【解决方案1】:

您可以将[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; }

【讨论】:

    猜你喜欢
    • 2013-10-11
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    相关资源
    最近更新 更多