The code first approach creates database automatically.Now we will see how EF knows the database name and server while executing code first approach.
The Entity Framework knows by seeing the parameter in the constructor of context class.
There are 3 parameters which are accepeted by EF.
No Parameter:
namespace CustomerDatalayer
{
public class CustomerContext:DbContext
{
public CustomerContext():base(){}
public DbSet
public DbSet
public DbSet
}
}
Database Name:
namespace CustomerDatalayer
{
public class CustomerContext:DbContext
{
public CustomerContext():base('CustomerDB'){}
public DbSet
public DbSet
public DbSet
}
}
Connection String Name:
namespace CustomerDatalayer
{
public class CustomerContext:DbContext
{
public CustomerContext():base('name=CustomerDBConnectionString'){}
public DbSet
public DbSet
public DbSet
}
}