Entity Framework CodeFirst : Where is my database
Sometime back I was trying out on CodeFirst and I suddenly realized that the generated database by CodeFirst is missing. I had to see in SSMS what exactly got generated. So I did a trick to retrieve the database information
//Employee Entity
public class Employee
{
public int Id { get; set; }
public string FullName { get; set; }
}
public class HRContext : DbContext
{
public DbSet<Employee> Emps { get; set; }
}
class Program
{
static void Main(string[] args)
{
var emp = new Employee() { FullName = "Wriju Ghosh" };
using (var ctx = new HRContext())
{
//This would get me the database information
string strConnection = ctx.Database.Connection.ConnectionString;
Console.WriteLine(strConnection);
ctx.Emps.Add(emp);
ctx.SaveChanges();
}
}
}
The output connection string would look like
Data Source=(localdb)\v11.0;Initial Catalog=ConsoleApplication1.HRContext;Integr ated Security=True;MultipleActiveResultSets=True
Namoskar!!!