I'm testing how code first works. Here's how I defined the Context
public class EfDbContext: Context
{
public DbSet<Client> Clients { get; set; }
}
I didn't create any data base, but I was able to do all the CRUD operations.
Now I don't see the connection string in my web.config. I don't see either the Database. I've checked the App_Data Directory and also the Sql Server Express. I don't see any trace of the Database created.
Yet, everything is perfectly.
EF code-first will use a connection string that has the same name as your DB context - so you could define it like this:
The database won't be created by default, until you actually do something, e.g. it should show up as soon as you make a call to
EfDbContext.SaveChanges()
for the first time.It will be called the same as your DB context (
YourNamespace.EfDbContext
) if you haven't defined your own, custom connection string, and it should show up in your default local SQL instance.See from the ADO.NET EF 4.1 Code First Walkthrough: