繁体   English   中英

代码优先方法实体框架核心中的表不加fk对性能更好吗

[英]Is it better for performance not to add fk to tables in the code first approach entity framework core

有个话题我很想知道朋友。 我首先运行 EntityFrameworkCore 代码,在一篇文章中我遇到了一个表达式:“如果您需要虚拟作业,请参阅 Include ()。” 现在,如果我删除表中的所有外键,性能更好还是有效果。

谢谢

无论您是否在 model 中包含 FK,Ef 核心都会生成 FK。

例如

示例来源: https://docs.microsoft.com/en-us/ef/core/modeling/shadow-properties

class MyContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }
}

public class Blog
{
    public int BlogId { get; set; }
    public string Url { get; set; }

    public List<Post> 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; }
}

“例如,以下代码清单将导致将 BlogId 影子属性引入 Post 实体。”

因此,总而言之,删除它们不会影响您的查询性能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM