C# EntityFramework CodeFirst数据库不';t更新

C# EntityFramework CodeFirst数据库不';t更新,c#,winforms,entity-framework,ef-code-first,sql-server-ce,C#,Winforms,Entity Framework,Ef Code First,Sql Server Ce,一天前,我开始在简单Windows窗体项目(C#)中使用实体框架代码优先。我创建了两个模型: [Table("SavesSet")] public partial class Saves { public Saves() { this.SkillsSet = new HashSet<Skills>(); } [Key] public int SaveID { get; set; } public string Pla

一天前,我开始在简单Windows窗体项目(C#)中使用实体框架代码优先。我创建了两个模型:

[Table("SavesSet")]
public partial class Saves
{
    public Saves()
    {
        this.SkillsSet = new HashSet<Skills>();
    }

    [Key]
    public int SaveID { get; set; }

    public string Player { get; set; }
    public int Age { get; set; }
    public int Money { get; set; }

    public virtual ICollection<Skills> SkillsSet { get; set; }
}

[Table("SkillsSet")]
public partial class Skills
{
    [Key]
    public int SkillID { get; set; }

    public string Name { get; set; }
    public int Value { get; set; }
    public int SavesSaveID { get; set; }

    public virtual Saves SavesSet { get; set; }
}
但当我开始程序调试时,ListView是空的。我设置了断点,查看了局部变量,发现SavesSet计数为0

我通过代码添加了一行:

Saves s = new Saves();
s.Player = "TestName";
s.Age = 5110;
s.Money = 200;
db.SavesSet.Add(s);
db.SaveChanges();
ListView显示了这个。但在我的数据库中什么都没有(它的大小也没有改变)。我重新启动了VisualStudio,但我的问题仍然存在:ListView显示了该项,但数据库是空的。我在App.Config和VS数据库浏览器中检查了ConnectionString,它们是相等的

所以,我的问题是:我如何探索我真正的数据库,它存储在哪里

更新。

我的数据库上下文:

    public SavesContext()
        : base("Saves")
    {
    }

    public DbSet<Saves> SavesSet { get; set; }
    public DbSet<Skills> SkillsSet { get; set; }
public SavesContext()
:base(“保存”)
{
}
公共DbSet SavesSet{get;set;}
公共DbSet SkillsSet{get;set;}
和我的App.Config:

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="TextSim.Properties.Settings.Saves" connectionString="Data          
            Source=C:\Documents and Settings\My\My Documents\visual studio       
            2010\Projects\TextSim\TextSim\Saves.sdf"
            providerName="System.Data.SqlServerCe.3.5" />
        </connectionStrings>
     </configuration>

实体框架使用了一种称为“约定优先于配置”的方法,这意味着如果您不为某些内容提供值,它将使用默认值

如果不指定连接字符串,它将使用从EF的命名空间和DbContext名称派生的默认连接字符串。如果是这种情况,那么它将使用默认系统创建一个新的(空白)数据库,而不使用您在Web.Config中配置的数据库


因此,当您保存东西时,它确实保存了,只是保存到了错误的数据库。

断开连接并重新连接(右键单击数据库)谢谢您的评论,但我已经尝试过很多次了。它不起作用。你能给我们看一下你的连接字符串吗?我尝试了两个连接字符串-它们都不起作用:“数据源=|数据目录|/Saves.sdf”和“数据源=C:\Documents and Settings\My\My Documents\visual studio 2010\Projects\TextSim\TextSim\Saves.sdf”。我很惊讶这两个字符串都能起作用,因为您的连接字符串与您配置的名称不同。您的dbcontext应该是
base(“name=TextSim.Properties.Settings.Saves”)
Hmm。我将App.Config中的连接字符串从“数据源=| DataDirectory |/Saves.sdf”更改为“数据源=C:\Documents and Settings\my\my Documents\visualstudio 2010\Projects\TextSim\TextSim\Saves.sdf”。程序不显示实数基的值——它显示我从代码创建的行。
<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <configSections>
        </configSections>
        <connectionStrings>
            <add name="TextSim.Properties.Settings.Saves" connectionString="Data          
            Source=C:\Documents and Settings\My\My Documents\visual studio       
            2010\Projects\TextSim\TextSim\Saves.sdf"
            providerName="System.Data.SqlServerCe.3.5" />
        </connectionStrings>
     </configuration>