当前位置:网站首页>EF core learning notes: additional foreign key attributes / single navigation attributes
EF core learning notes: additional foreign key attributes / single navigation attributes
2022-07-21 02:37:00 【Director Dong】
Although we have been doing customized development , But you can't always eat what you want . Many things you must master .
Additional foreign key attributes
Why do you need foreign key attributes
1、EF Core Foreign key columns will be created in the data table .
2、 If you need to get the value of the foreign key column , You need to do association query , Low efficiency .( Various join)
3、 Need a kind of unnecessary Join Get the value of the foreign key column directly .
Set foreign key properties
1、 Explicitly declare a foreign key attribute in the entity class .
2、 Relationship configuration through HasForeignKey(c=>c.ArticleId) Specify this attribute as a foreign key .
3、 Unless necessary , Otherwise, don't declare , Because repetition will be introduced .
Then remember to configure ! Otherwise EFcore I don't know where this foreign key comes from .
Review the hasOne( )
Single navigation attribute
The trouble of two-way navigation properties : Many tables will refer to the same table , such ,user There will be many tables In reverse Navigation properties .
It is not necessary to
So we need a single navigation attribute .
Requestor and Approved by All point to user surface
Configuration method
Do not set the reverse attribute , And then when configuring WithMany() Do not set parameters .
How can one-way attributes get data in reverse
// Just check again :
ctx.Leaves.Where(l => l.Requester == u)
For the master-slave structure “ One to many ” Table relations , It is generally to declare bidirectional navigation properties .
And for the rest “ One to many ” Table relations : If the table belongs to the basic table referenced by many tables , Then use the single navigation attribute , Otherwise, you can freely decide whether to use the two-way navigation attribute .
Considering the possibility of having a single navigation attribute , We usually use HasOne().WithMany()
边栏推荐
- Trax:如何打赢夏日冰淇淋市场的甜蜜之战?
- 软件测试职业发展方向(不要迷茫了,赶紧卷起来)
- 检查日期是否在其他两个日期之间
- 元宇宙 3D 开荒场
- HMS Core音频编辑服务支持7种音频特效,助力一站式音频处理
- excel怎么选取特定数字求和?excel选中特定数字求和的方法
- 百度交易中台之钱包系统架构浅析
- MySQL 字段值里包含_和\转义符,如何在比对两个表的值时消除影响?
- One article speed learning - basis of pyspark data analysis: detailed explanation of pyspark basic functions and basic grammar
- 【ArcGIS微课1000例】0029:ArcGIS绘制平行线(构造平行公路)
猜你喜欢
记录uni-app 打包成apk后获取定位
织梦DEDE后台系统用户管理显示空白的解决方法
织梦添加栏目修改栏目时提示“保存目录数据时失败,请检查你的输入资料是否存在问题”
Office软件无法正常启动0xc0000142怎么解决?
结构体完结(柔性数组)
Apache Flink 的 Per-Job 提交流程
在线问题反馈模块实战(八):实现图片上传功能(上)
请别再使用 SimpleDateFormat 格式化时间了,DateTimeFormatter 更出色!
Binary tree OJ exercise
Please stop using simpledateformat to format time. Datetimeformatter is better!
随机推荐
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
Real time debugging practice based on attach to process
swift 使用SMAMB2包,重新打包的心酸历程
Office软件无法正常启动0xc0000142怎么解决?
检查日期是否有效
使用 NSProxy 实现消息转发
ILRunitme foreach 存在GC
Capacity scheduling absolute value configuration queue usage and pit avoidance
Exploration and practice of dewu app data simulation platform
Per job submission process of Apache Flink
Inserting data in stored procedures and for loops
计算从今天开始的天数
Difi: a go as you pay Wi Fi access system intensive reading notes (II)
Interpreting the implementation principle of go Distributed Link Tracking
Please stop using simpledateformat to format time. Datetimeformatter is better!
China's first white paper on the application of electronic signatures in the construction industry was released
Redis application
金蝶上半年“答卷”预告:大客户战略持续突破,ARR同比增长45%以上
Can the tidb of a single machine be used in the production environment?