.net - Entity Framework 类可以有非 Entity Framework 成员吗?

标签 .net entity-framework

我在数据库中有某些我想要的属性,但我是否可以在数据库中的同一类中也有我不想要的函数和成员?这是一个坏主意吗?

最佳答案

函数不存储在数据库中。您可以从数据库映射中排除成员(属性或类不会存储在数据库中)。您可以使用 NotMapped 来做到这一点属性:

[NotMapped]
public string Bar { get; set; }

或使用 Ignore在流畅的映射中:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Foo>().Ignore(f => f.Bar);
    base.OnModelCreating(modelBuilder);
}

关于.net - Entity Framework 类可以有非 Entity Framework 成员吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15010822/

相关文章:

c# - 如何在我的自定义类上使用 IDisposable?

c# - Web 浏览器控件 : Disable Cross Site XSS Filtering or another way to process JS in full on HTML

C# - 追加文本文件

c# - Entity Framework 6 防止删除

c# - 在 LINQ to Entities 中使用未建模的对象集合

entity-framework - Code First Entity Framework 和 Windows Azure SQL

c# - 哪个日志实用程序适用于 C# 中的 .NET 应用程序(ASP.NET、WinForms)?

c# - 如何按键查找/检查字典值

c# - 多次使用 Include() 时 Entity Framework 代码很慢

java - 将架构名称添加到 Spring 数据中的实体?