Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架代码首先对SQL Server执行很长的查询_C#_Sql_Sql Server_Entity Framework_Ef Code First - Fatal编程技术网

C# 实体框架代码首先对SQL Server执行很长的查询

C# 实体框架代码首先对SQL Server执行很长的查询,c#,sql,sql-server,entity-framework,ef-code-first,C#,Sql,Sql Server,Entity Framework,Ef Code First,我正在学习EF代码优先的方法,我有很长的查询问题 我有以下DB类: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public virtual List<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } pub

我正在学习EF代码优先的方法,我有很长的查询问题

我有以下DB类:

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

    public virtual List<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }

    public int BlogId { get; set; }
    public virtual Blog Blog { get; set; }
}

public class BloggingContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Post> Posts { get; set; }
}
此查询花费3秒以上的时间添加一行!正在SQL Server Express LocalDb中添加生成。我更改了它,现在在SQLServerCompact中添加了数据,但什么也没发生!添加查询的时间很长

当我使用数据库优先和模型优先的方法时,一切都很好,很快


先编写代码有什么问题?

添加第二行需要多长时间?在第一次
SaveChanges()
之后,创建一个新博客,添加它并保存它。momental,我忘记了第一次查询很长。谢谢
using (var db = new BloggingContext())
        {                
            Console.WriteLine("Enter a name for a new Blog: ");
            var name = Console.ReadLine();

            var blog = new Blog { Name = name };
            db.Blogs.Add(blog);
            db.SaveChanges();
        }