原文地址:[https://docs.efproject.net/en/latest/modeling/included-properties.html][1]

在模型中包含一个属性意味着 EF 拥有了这个属性的元数据并且将尝试在数据库中进行读写属性的值。

内容导航

  • [约定][2]
  • [Data Annotation][3]
  • [Fluent API][4]

约定

根据约定,带有 getter 和 setter 的公共属性将被包含在模型中。

Data Annotations

我们可以使用 Data Annotaions 来从模型中排除一个属性。

public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; } [NotMapped] // 人工高亮
public DateTime LoadedFromDatabase { get; set; }
}

Fluent API

我们可以使用 Fluent API 来从模型中排除一个属性。
```
class MyContext : DbContext
{
public DbSet Blogs { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().Ignore(b => b.LoadedFromDatabase); // 人工高亮
}

}

public class Blog

{

public int BlogId { get; set; }

public string Url { get; set; }

public DateTime LoadedFromDatabase { get; set; }

}



  [1]: https://docs.efproject.net/en/latest/modeling/included-properties.html
[2]:#1
[3]:#2
[4]:#3

EntityFramework Core 学习笔记 —— 包含与排除属性的更多相关文章

  1. EntityFramework Core 学习笔记 —— 包含与排除类型

    原文地址:https://docs.efproject.net/en/latest/modeling/included-types.html 在模型类中包含一种类型意味着 EF 拥有了这种类型的元数据 ...

  2. EntityFramework Core 学习笔记 —— 创建模型

    原文地址:https://docs.efproject.net/en/latest/modeling/index.html 前言: EntityFramework 使用一系列的约定来从我们的实体类细节 ...

  3. EntityFramework Core 学习笔记 —— 添加主键约束

    原文地址:https://docs.efproject.net/en/latest/modeling/keys.html Keys (primary) Key 是每个实体例的主要唯一标识.EF Cor ...

  4. EntityFramework Core 学习系列(一)Creating Model

    EntityFramework Core 学习系列(一)Creating Model Getting Started 使用Command Line 来添加 Package  dotnet add pa ...

  5. .NET CORE学习笔记系列(2)——依赖注入[7]: .NET Core DI框架[服务注册]

    原文https://www.cnblogs.com/artech/p/net-core-di-07.html 包含服务注册信息的IServiceCollection对象最终被用来创建作为DI容器的IS ...

  6. .NET CORE学习笔记系列(2)——依赖注入[6]: .NET Core DI框架[编程体验]

    原文https://www.cnblogs.com/artech/p/net-core-di-06.html 毫不夸张地说,整个ASP.NET Core框架是建立在一个依赖注入框架之上的,它在应用启动 ...

  7. .NET CORE学习笔记系列(2)——依赖注入【3】依赖注入模式

    原文:https://www.cnblogs.com/artech/p/net-core-di-03.html IoC主要体现了这样一种设计思想:通过将一组通用流程的控制权从应用转移到框架中以实现对流 ...

  8. .NET CORE学习笔记系列(2)——依赖注入【1】控制反转IOC

    原文:https://www.cnblogs.com/artech/p/net-core-di-01.html 一.流程控制的反转 IoC的全名Inverse of Control,翻译成中文就是“控 ...

  9. .NET CORE学习笔记系列(2)——依赖注入[5]: 创建一个简易版的DI框架[下篇]

    为了让读者朋友们能够对.NET Core DI框架的实现原理具有一个深刻而认识,我们采用与之类似的设计构架了一个名为Cat的DI框架.在上篇中我们介绍了Cat的基本编程模式,接下来我们就来聊聊Cat的 ...

随机推荐

  1. bootstrap学习笔记之三(组件的使用)

    bootstrap组件需要引入bootstrap.js才行,当然要引入bootstrap.js首先得引入JQuery. 一.下拉菜单 将下拉菜单触发器和下拉菜单都包裹在 .dropdown 里,或者另 ...

  2. asp.net identity 2.2.0 中角色启用和基本使用(七)提示点

    在使用asp.net identity 2.2.0 中,大家可能设计到一些修改和配置 关于Identity的配置,在App_Start文件中的IdentityConfig.cs中,这里几乎有你需要的一 ...

  3. Thinking in Java——笔记(10)

    Inner Classes It allows you to group classes that logically belong together and to control the visib ...

  4. ionic2安装时报错

    Installing npm packages...Error with start undefinedError Initializing app: There was an error with ...

  5. Assets和Raw区别

    在建立项目中一般会默认建立assets文件,当然我们还可以在res文件下面建立raw文件夹,这里面都可以存放一些多媒体文件或者文本信息,可以供我们在程序中使用. assets下面的文件不会被编译,通过 ...

  6. MVC+EF OA观看视频记录

    搭建基本框架 创建基接口: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  7. Nginx基础整理

    目录结构如下: Nginx基础知识 Nginx HTTP服务器的特色及优点 Nginx的主要企业功能 Nginx作为web服务器的主要应用场景包括: Nginx的安装 安装环境 快速安装命令集合 各个 ...

  8. PL/SQL 存储函数和过程

    --存储过程 .不带参: create or replace procedure 存储过程名 as|is --说明部分 begin --执行的语句: end: 调用存储过程 execute 存储过程名 ...

  9. JQuery兼容IE6问题汇总(不断更新)

    兼容IE6真是苦逼的差事,无奈中... 逗号的问题:IE6中要去掉最后的逗号 var o={ id:1, Name:"abc", //这里的逗号一定要去掉 } HTML的结构,由于 ...

  10. delphi之动态库调用和串口通讯

    串口通讯: Spcomm 控件属性: CommName  :表示COM1,COM2等串口的名字: BaudRate:设定波特率9600,4800等 StartComm StopComm 函数Write ...