Note that there are some explanatory texts on larger screens.

plurals
  1. POEF savechanges() does not effect on my .mdf DB
    primarykey
    data
    text
    <p>I have this model on my .mdf DB:</p> <p><img src="https://i.stack.imgur.com/uMzw8.png" alt="enter image description here"></p> <p>these 2 tables with no data:</p> <p><img src="https://i.stack.imgur.com/e3D3C.png" alt="enter image description here"></p> <p>PersonID is a foreign key. </p> <p>This is my EF model diagram:</p> <p><img src="https://i.stack.imgur.com/hyAqp.png" alt="enter image description here"></p> <p>And this is the code for adding a person.</p> <pre><code> namespace DBTest { class Class1 { MyDBEntities db; public Class1() { db = new MyDBEntities(); AddPerson(); } void AddPerson() { Person p = new Person(); p.ID=1; p.NAME="abcd"; db.AddToPerson(p); db.SaveChanges(); } } } </code></pre> <p>After I call to the class from the main:</p> <pre><code> namespace DBTest { class Program { static void Main(string[] args) { Class1 a = new Class1(); } } } </code></pre> <p>I want to see if there's any change in my .mdf DB.<br> I find that the database is still empty (after refreshing):</p> <p><img src="https://i.stack.imgur.com/e3rUy.png" alt="enter image description here"></p> <p>Does anyone have an idea what I need to do to cause the database to be updated? What am I doing wrong? </p> <p>EDIT:</p> <p>The connection string:</p> <pre><code> &lt;connectionStrings&gt; &lt;add name="DBTest.Properties.Settings.XXXXConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\XXXX.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /&gt; &lt;add name="MyDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&amp;quot;" providerName="System.Data.EntityClient" /&gt; &lt;/connectionStrings&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