Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.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# 数据库未在Visual Studio中显示_C#_Database_Visual Studio 2010 - Fatal编程技术网

C# 数据库未在Visual Studio中显示

C# 数据库未在Visual Studio中显示,c#,database,visual-studio-2010,C#,Database,Visual Studio 2010,我正在Visual Studio中使用C#开发一个应用程序。这是我的第一个C#应用程序,它将使用本地数据库,因此我不确定这是如何实现的。 我一直在关注codeguru 我已经声明了我的实体,所有这些实体目前都只是继承自: public class Reference { /// <summary> /// ID of the reference. /// </summary> public int Id { get; set; }

我正在Visual Studio中使用C#开发一个应用程序。这是我的第一个C#应用程序,它将使用本地数据库,因此我不确定这是如何实现的。 我一直在关注codeguru

我已经声明了我的实体,所有这些实体目前都只是继承自:

public class Reference
{
    /// <summary>
    /// ID of the reference.
    /// </summary>
    public int Id { get; set;  }

    /// <summary>
    /// Reference to the element in theTVDB.
    /// </summary>
    public int TheTVDBId { get; set; }

    /// <summary>
    /// Whether or not the reference has been marked as watched.
    /// </summary>
    public bool IsWatched { get; set; }
}
所有这些似乎都奏效了。至少,我没有收到任何错误,
I
每次运行都是2

问题是数据库(名为“库”)没有显示在任何地方。事实上,我甚至没有“对象浏览器”视图,而且我似乎找不到它。 由于数据库没有显示,我不确定这是否有效,以及我的数据是否实际存储


有人知道我做错了什么或者我遗漏了什么吗?

我似乎已经解决了这个问题

我做了以下工作:

public class Library : DbContext
{
    /// <summary>
    /// Constructor using the base constructor.
    /// This constructor names the database "Library".
    /// </summary>
    public Library() : base("Library")
    {
    }

    /// <summary>
    /// Set of TVSeriesReferences stored in the database.
    /// </summary>
    public DbSet<TVSeriesReference> TVSeriesReferences { get; set; }

    /// <summary>
    /// Set of SeasonReferences stored in the database.
    /// </summary>
    public DbSet<SeasonReference> SeasonReferences { get; set; }

    /// <summary>
    /// Set of EpisodeReferences stored in the database.
    /// </summary>
    public DbSet<EpisodeReference> EpisodeReferences { get; set; }
}
Library db = new Library();

TVSeriesReference reference1 = new TVSeriesReference();
reference1.TheTVDBId = 1234;
reference1.IsWatched = true;
db.TVSeriesReferences.Add(reference1);

TVSeriesReference reference2 = new TVSeriesReference();
reference2.TheTVDBId = 8000;
db.TVSeriesReferences.Add(reference2);

int i = db.SaveChanges();
  • 在服务器资源管理器中,我右键单击数据连接,选择“添加连接…”并创建了一个Microsoft SQL Server。我将服务器名设置为
    \SQLEXPRESS
    ,将数据库名设置为
    Library
  • 然后,我将以下内容添加到
    app.config
    : 它现在似乎起作用了
  • 
    
    从“视图”菜单中选择“服务器资源管理器”。你的数据库应该在那里。或者,您在解决方案资源管理器中看到EDMX文件了吗?我在服务器资源管理器中没有看到任何数据库,也没有在解决方案资源管理器中看到任何EDMX文件。这就是我所看到的一切。我想再谈这个,但我现在真的帮不了你,对不起。我以前有过这个问题,所以我会看看我是否保存了关于它的任何注释。实际上,我刚刚发现了这个问题。下面的答案可能会有所帮助:我尝试了答案中的建议,但似乎没有一个有效。没有app_数据目录,即使我添加了自己的数据连接(添加了一个.mdf文件),也没有表添加到此数据库。也许我错过了一些基本的步骤。我不太确定,因为这是我第一次尝试在C#/Visual Studio项目中创建数据库。它似乎可以工作,但现在可以了。这两个问题可能有关联,但我不确定。