C# ASP.net MVC-属性未映射到数据库

C# ASP.net MVC-属性未映射到数据库,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,模型中是否可能存在未映射到数据库列中的属性 我将ASP.net实体框架与MVC 5一起使用。您可以使用以下属性: public class SomeModel { public int MappedProperty { get; set; } [NotMapped] public int UnmappedProperty { get; set; } } 或者使用fluent API: protected override void OnModelCreating(Db

模型中是否可能存在未映射到数据库列中的属性


我将ASP.net实体框架与MVC 5一起使用。

您可以使用以下属性:

public class SomeModel
{
    public int MappedProperty { get; set; }

    [NotMapped]
    public int UnmappedProperty { get; set; }
}
或者使用fluent API:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Entity<SomeModel>().Ignore(m => m.UnmappedProperty );
   base.OnModelCreating(modelBuilder);
}

您正在使用实体框架吗?代码优先还是设计师?答案是肯定的,但需要更多细节。我正在使用ASP.net实体框架和MVC 5,代码优先。但它是代码优先还是模型优先?是的,这将取决于您如何构建解决方案。更多地解释你的代码结构?代码优先是我正在使用的。