c# - EF can't SaveChanges to db -


I try to create a equation unit and add it to SQL Server DB I do not get any error in my code but I do not see any change in the DB.

I check DB in Visual Studio in Server Explorer, and the value is not added to it. DB was added to the project when I was making an EFF data model for it in my project so that Visual Studio created a copy of DB in my project. But I do not know why two copies were made in the project directory and / bind / debug directory.

Entity class:

  Public partial equation {public equation () {This.Results = new hashset & lt; Results & gt; (); } Receive public ID { Set; } Public Double A {get; Set; } Public Double B {get; Set; } Public Double C {get; Set; } Public virtual iconging & lt; Results & gt; Results {get; Set; }}  

ID is the primary key and the identity is (1,1)

My code:

  Private EquationDBEntities = new dbcontext EquationDBEntities (); Equation eq = new equation () {a = 1, b = 2, c = 3}; Dbcontext.Equations.Add (eq); Dbcontext.SaveChanges (); DbContext: Public partial class EquationDBEntities: DbContext {Public EquationDBEntities (): Base ("name = EquationDBEntities") {} Protected Override Zero OnModelCreating ( DbModelbuilder modelBuilder) {New UnintentionalCodeFirstException (); } Public Virtual DbSet & lt; Equation & gt; Equation {get; Set; } Public Virtual DbSet & lt; Results & gt; Results {get; Set; }  

Consection string:

  & lt; Connection best & gt; Provider = System.Data.SqlClient; //*/EquationDBModel.msl: |: Race | //*/EquationDBModel.csdl: //*/EquationDBModel.ssdl race; & Lt Add Name = "EquationDBEntities" connectionstring = "Metadata = Race; Provider Connection String = & amp; quot; Data Source = (LocalDB) \ v11.0; attachdbfilename = | DataDirectory | \ EquationDB.mdf; Integrated Security = True; Connect timeout = 30; MultipleActiveResultSets = true; Application = EntityFramework & amp; quot; "Provider name =" System.Data.EntityClient "/> & Lt; / ConnectionStrings & gt;  

AP Project configuration with Ef model (I refer it to my current project)

  & lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; Configuration & gt; & Lt; ConfigSections & gt; & Lt; -! For more information about the structure of the unit, see http://go.microsoft.com/fwlink/?LinkID=237468 - & gt; & Lt; Section name = "entityFramework" type = "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, version = 6.0.0.0, culture = neutral, publicKeyToken = b77a5c561934e089" requirePermission = "false" /> & Lt; / ConfigSections & gt; & Lt; ConnectionStrings & gt; & Lt; Add name = "equation DBEntities" connectionString = "metadata = res: //*/EquationDBModel.csdl | res: //*/EquationDBModel.ssdl | res: //*/EquationDBModel.msl; provider = System.Data.SqlClient; Provider Connection String = & amp; amp; quot; Data Source = (LocalBD) \ v11.0; attachdbfilename = | DataDirectory | \ Equation DB.MDF; Integrated Security = True; Connect Timeout = 30; MultipleActiveResultset = True; App = Entity Framework & Amp; quot; "Provider Name =" System.Data.EntityClient "/> & Lt; / ConnectionStrings & gt; & Lt; EntityFramework & gt; & Lt; DefaultConnectionFactory type = "System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" & gt; & Lt; Parameters & gt; & Lt; Parameter value = "v11.0" /> & Lt; / Standards & gt; & Lt; / DefaultConnectionFactory & gt; & Lt; Providers & gt; & Lt; Provider invariantName = "System.Data.SqlClient" type = "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> & Lt; / Providers & gt; & Lt; / EntityFramework & gt; & Lt; / Configuration & gt;  

Any ideas?

This is because | Data directory The replacement string means that the database subfolder used by your application is located in BIN \ DEBUG . But when you add a database to your project, it creates two copies, one of the project folders and the other BIN \ DEBUG and you expect this change to be done in the database from the project folder Dawn is not seeing anything in Explorer because it probably has a wrong connection.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -