There are examples of connection strings in documentation to CF, but they are strange and looks non-standard. For example, instead of "Data Source" parameter, there is a "Server" parameter. Also no examples of how to set connection string to SQL server
with SQL Server authentication. I have no SQL server on my machine and I don't want to install it.
You write a connection string for Code First the same way as you do for ADO.NET.
(here the meaning of "Server" the same as "Data Source" attribute; you can find some information on that matter here http://www.techrepublic.com/article/educate-yourself-about-net-sql-server-connection-string-syntax/6084879 )
But you should know when database initialization code is run:
- when you call Database.SetInitializer method - it performs only registration of a IDatabaseInitializer<TContext> object with your Context; but doesn't execute any code from it;
- EF creates your EDM only when you construct your Context object the first time;
- all modification to your database (creating database, running the code in your DBContextInitializer class to Seed data) happens only when you request data from your context (it means from your database as well) the first time.
// no model EDM exists here yet// no database initialization code is run yetusing(var context = new MyContext())
// EDM is constructed// no database initialization code is run yetvar query = context.Companies.FirstOrDefault();
// database initialization code has been run to this point
Hope this helps.
Proposed as answer byKris444Friday, September 30, 2011 1:24 AM