Entity Framework Code First将根据Model在数据库库中自动创建一个表。
有没有一个属性可以避免这种情况?
发布于 2012-05-13 22:17:29
将[System.ComponentModel.DataAnnotations.Schema.NotMapped]属性添加到属性中。
发布于 2014-01-01 04:24:52
根据accepted answer和similar question/answer,除了[NotMapped]之外,您还可以使用Fluent API指定它:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty);
base.OnModelCreating(modelBuilder);
}发布于 2015-03-12 01:56:39
如果你喜欢简明扼要,[NotMapped]是一个简短的版本。当然,您还可以添加以下内容:
using System.ComponentModel.DataAnnotations.Schema;给你的班级。
https://stackoverflow.com/questions/10572442
复制相似问题