I try to create an Equation entity and to add it to SQL Server db, i do not get any errors in my code but i do not see any changes in the db.
I check the db in the server explorer in visual studio, and there are not added values. The db were added to the project when i was creating the ef data model for it in my project so the visual studio made a copy of the db in my project. But i don't know why it created two copies, in the project directory and /bind/Debug directory.
Entity Class:
public partial class Equation { public Equation() { this.Results = new HashSet<Result>(); } public int id { get; set; } public double a { get; set; } public double b { get; set; } public double c { get; set; } public virtual ICollection<Result> Results { get; set; } } id is primary key and has identity(1,1)
My code:
private EquationDBEntities dbcontext = new 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 void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<Equation> Equations { get; set; } public virtual DbSet<Result> Results { get; set; } conectionString:
<connectionStrings> <add name="EquationDBEntities" connectionString="metadata=res://*/EquationDBModel.csdl|res://*/EquationDBModel.ssdl|res://*/EquationDBModel.msl; provider=System.Data.SqlClient; provider connection string=" data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\EquationDB.mdf; integrated security=True;connect timeout=30; MultipleActiveResultSets=True;App=EntityFramework" " providerName="System.Data.EntityClient" /> </connectionStrings> App.Config of project with ef model(i reference it from my current project)
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <connectionStrings> <add name="EquationDBEntities" connectionString="metadata=res://*/EquationDBModel.csdl|res://*/EquationDBModel.ssdl|res://*/EquationDBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\EquationDB.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> </configuration> Any ideas ?