Note that there are some explanatory texts on larger screens.

plurals
  1. POEntityFramework CodeFirst Database doesn't update
    primarykey
    data
    text
    <p>One day ago I started using Entity Framework CodeFirst in simple Windows Forms project (C#). I created two models:</p> <pre><code>[Table("SavesSet")] public partial class Saves { public Saves() { this.SkillsSet = new HashSet&lt;Skills&gt;(); } [Key] public int SaveID { get; set; } public string Player { get; set; } public int Age { get; set; } public int Money { get; set; } public virtual ICollection&lt;Skills&gt; 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; } } </code></pre> <p>Then I added one row into my database using Visual Studio Database Explorer (local database using SqlServerCe 3.5):</p> <p>SaveID = 1</p> <p>Player = "TEST"</p> <p>Age = 1</p> <p>Money = 1</p> <p>I also created form with ListView and wrote some code:</p> <pre><code>private SavesContext db = new SavesContext(); foreach (Saves s in db.SavesSet.ToList()) { ListViewItem l = new ListViewItem(); l.Name = s.SaveID.ToString(); l.Text = s.Player; ListViewSaves.Items.Add(l); } </code></pre> <p>But when I started program debugging ListView was empty. I set breakpoint, viewed local variables and saw that SavesSet count was 0.</p> <p>I added one row via code:</p> <pre><code>Saves s = new Saves(); s.Player = "TestName"; s.Age = 5110; s.Money = 200; db.SavesSet.Add(s); db.SaveChanges(); </code></pre> <p>And ListView displayed this one. But in my database there was nothing (and its size didn't change). I restarted Visual Studio - and my trouble was still actual: ListView shows item, but database was empty. I checked ConnectionString in App.Config and in VS Database Explorer - they were equal.</p> <p>So, my question is: How can I explore my real database and where does it stores?</p> <p><strong>Update.</strong></p> <p>My DbContext:</p> <pre><code> public SavesContext() : base("Saves") { } public DbSet&lt;Saves&gt; SavesSet { get; set; } public DbSet&lt;Skills&gt; SkillsSet { get; set; } </code></pre> <p>And my App.Config:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;/configSections&gt; &lt;connectionStrings&gt; &lt;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" /&gt; &lt;/connectionStrings&gt; &lt;/configuration&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload