Entity Framework not saving changes to a Local DB

c# entity-framework-6 winforms


I'm attempting to create an application to expand my understanding of C# and Entity Framework.

I believe I have everything set up properly since there are no errors. My inability to add a new record to localDb in Visual Studio 2017 is the issue.

Any thoughts? I appreciate it.

The code is below.

private void Save_btn_Click(object sender, EventArgs e)
        var context = new Database1Entities();

        var aMemberdef = new Members()
            FirstName = Name_txt.Text,
            LastName = LastName_txt.Text


here's myapp.config :

<?xml version="1.0" encoding="utf-8"?>
        <section name="entityFramework" 
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                 requirePermission="false" />
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        <add name="Database1Entities" 
             connectionString="metadata=res://*/EF.Model1.csdl|res://*/EF.Model1.ssdl|res://*/EF.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB; attachdbfilename=|DataDirectory|\Data\Database1.mdf; initial catalog=Database1; integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
             providerName="System.Data.EntityClient" />
             type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
            <provider invariantName="System.Data.SqlClient" 
                      type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

Although I believe the app configuration file contains a mistake, entity framework created the connection string. I'm therefore trapped at MyDB Architecture

4/20/2017 10:31:42 AM

Popular Answer

because each time you run localdb, a copy is made in the bin folder. Every every time you run or debug it, it is overwritten. The project folder's main file has not been changed. Answer in full: https://social.msdn.microsoft.com/Forums/en-US/393bddc6-0b85-4c27-9475-27172e50d2d9/entity-framework-doesnt-save-new-record-into-database?forum=adodotnetentityframework

8/12/2018 6:10:17 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow