I am using MVC3 with Code first approach. In this case, I had to generate my entity classes from the existing databse.
The database was
Database1.mdf
Once I did that, it created DBEntities and added a new connectionstring in my Web.config which looked something like this:
<add name="DATABASE1Entities" connectionString="metadata=res://*/Models.Task.csdl|res://*/Models.Task.ssdl|res://*/Models.Task.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\DATABASE1.MDF;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Now I removed DB Entities and came up with my own DB Context class.
and
Now, I am working with the following connectionstring:
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|DATABASE1.mdf;User Instance=true" providerName="System.Data.SqlClient" />
Name of my DBcontext class is TaskContext.
I am not sure what happeend afer this. My code works. But it works on some blank database and it does not reflect anydata in database.mdf. If I add something using my controller then I see that thing is added. But it does not get reflected in Databse1.mdf.
It seeems to have created a its own databse. But I do not see andy .sdf or .mdf file created anywhere.... I am not sure what is going on?