博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET CORE Shadow Properties
阅读量:6334 次
发布时间:2019-06-22

本文共 1867 字,大约阅读时间需要 6 分钟。

hot3.png

Shadow properties are properties that are not defined in your .NET entity class but are defined for that entity type in the EF Core model. The value and state of these properties is maintained purely in the Change Tracker.

Shadow properties are useful when there is data in the database that should not be exposed on the mapped entity types. They are most often used for foreign key properties, where the relationship between two entities is represented by a foreign key value in the database, but the relationship is managed on the entity types using navigation properties between the entity types.

https://docs.microsoft.com/en-us/ef/core/modeling/shadow-properties

For example, the following code listing will result in a BlogId shadow property being introduced to the Post entity.

class MyContext : DbContext{    public DbSet
Blogs { get; set; } public DbSet
Posts { get; set; }}public class Blog{ public int BlogId { get; set; } public string Url { get; set; } public List
Posts { get; set; }}public class Post{ public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public Blog Blog { get; set; }}

If the name supplied to the Property method matches the name of an existing property (a shadow property or one defined on the entity class), then the code will configure that existing property rather than introducing a new shadow property.

class MyContext : DbContext{    public DbSet
Blogs { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity
() .Property
("LastUpdated"); }}public class Blog{ public int BlogId { get; set; } public string Url { get; set; }}

173058_HVj0_3556610.png

转载于:https://my.oschina.net/u/3556610/blog/1613060

你可能感兴趣的文章
[Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction...
查看>>
FFMPEG中关于ts流的时长估计的实现(转)
查看>>
Java第三次作业
查看>>
【HDOJ 3652】B-number
查看>>
android代码混淆笔记
查看>>
Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集
查看>>
BMP文件的读取与显示
查看>>
Flash文字效果
查看>>
各种排序算法总结篇(高速/堆/希尔/归并)
查看>>
使用c#訪问Access数据库时,提示找不到可安装的 ISAM
查看>>
Highcharts X轴纵向显示
查看>>
windows 注册表讲解
查看>>
【算法】论平衡二叉树(AVL)的正确种植方法
查看>>
基于DDD的现代ASP.NET开发框架--ABP系列之1、ABP总体介绍
查看>>
react 从零开始搭建开发环境
查看>>
scala recursive value x$5 needs type
查看>>
ps -ef |grep 输出的具体含义
查看>>
markdown编辑
查看>>
ASCII 在线转换器
查看>>
Linux内核同步:RCU
查看>>