在代码优先方法 entity framework 核心中不将 fk 添加到表中对性能是否更好

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

有个话题想问朋友。我首先是 运行 EntityFrameworkCore 代码,在一篇文章中我遇到了一个表达式:"If you need virtual jobs, see Include ()." 现在,如果我删除表中的所有外键,性能会更好还是有影响.

谢谢

无论您是否在模型中包含 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; }
}

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

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