【发布时间】:2012-05-21 07:04:22
【问题描述】:
Entity Framework Code First 将根据模型在数据库中自动创建一个表。
有没有属性可以避免这种情况?
【问题讨论】:
标签: entity-framework code-first
Entity Framework Code First 将根据模型在数据库中自动创建一个表。
有没有属性可以避免这种情况?
【问题讨论】:
标签: entity-framework code-first
[NotMapped] 是简洁的版本。当然,你会添加:
using System.ComponentModel.DataAnnotations.Schema;
到你的班级。
【讨论】:
根据accepted answer 和similar question/answer,除了[NotMapped],您还可以使用Fluent API 指定它:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty);
base.OnModelCreating(modelBuilder);
}
【讨论】:
【讨论】: