我正在运行下面的代码以学习代码优先的工作流程。代码完美编译并运行。我认为数据库是创建的,因为我可以在运行代码时看到以前的条目。但是我无法在Microsoft SQL Server Management Studio上看到数据库。当我刷新时,新的数据库和表。我可以在Visual Studio的Server Explorer上看到数据库。这是为什么?我怎样才能看到创建的数据库?这里是代码:执行代码优先代码后不会出现数据库
using System.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeFirstNewDatabaseSample
{
class Program
{
static void Main(string[] args)
{
using (var db = new BloggingContext())
{
Console.WriteLine("enter a new name for a new blog");
var name = Console.ReadLine();
var blog = new Blog { Name = name};
db.Blogs.Add(blog);
db.SaveChanges();
var query = from b in db.Blogs orderby b.Name select b;
Console.WriteLine("all blogs in database : ");
foreach(var item in query)
{
Console.WriteLine(item.Name);
}
Console.ReadLine();
}
}
}
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; }
}
}
是配置文件“App.config”的名称? – jason
如果您使用的是Web应用程序,那么该文件是App.config,如果您使用的是Web应用程序,那么它是Web.config – dotnetom