Performance 在代码优先方法实体框架核心中,不向表添加fk对性能是否更好

Performance 在代码优先方法实体框架核心中,不向表添加fk对性能是否更好,performance,entity-framework-core,ef-code-first,Performance,Entity Framework Core,Ef Code First,有一个话题我想问朋友们。我首先运行EntityFrameworkCore代码,在一篇文章中,我遇到了一个表达式:“如果需要虚拟作业,请参阅Include()”。现在,如果我删除表中的所有外键,性能是更好还是有效果 谢谢无论您的模型中是否包含FK,Ef core都将生成FK e、 g 示例来源: class MyContext:DbContext { 公共数据库集博客{get;set;} 公共DbSet Posts{get;set;} } 公共类博客 { public int BlogId{get

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


谢谢

无论您的模型中是否包含FK,Ef core都将生成FK

e、 g

示例来源:

class MyContext:DbContext
{
公共数据库集博客{get;set;}
公共DbSet Posts{get;set;}
}
公共类博客
{
public int BlogId{get;set;}
公共字符串Url{get;set;}
公共列表发布{get;set;}
}
公营职位
{
公共int PostId{get;set;}
公共字符串标题{get;set;}
公共字符串内容{get;set;}
公共博客Blog{get;set;}
}
例如,下面的代码列表将导致向Post实体引入BlogId shadow属性


总之,删除它们对查询的性能没有影响

非常感谢@mesies,我认为在这种情况下编写查询时使用的方法更重要,我理解正确。例如,延迟加载、急切加载。据我所知,这并不影响fk是否存在。是的,您的思路是正确的,试着想想linq查询将生成哪些sql命令,您就会没事了!
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; }
}