Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Entity Framework Code First 将根据模型在数据库中自动创建一个表。
有没有可以避免这种情况的属性?
将属性添加[System.ComponentModel.DataAnnotations.Schema.NotMapped]到属性。
[System.ComponentModel.DataAnnotations.Schema.NotMapped]
根据接受的答案和类似的问题/答案,除了[NotMapped]您还可以使用 Fluent API 指定它:
[NotMapped]
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<TheModelAffected>().Ignore(t => t.TheIgnoredProperty); base.OnModelCreating(modelBuilder); }
[NotMapped]如果您喜欢简洁,则为简短版本。当然,您会添加:
using System.ComponentModel.DataAnnotations.Schema;
到你的班级。