Author : MD TAREQ HASSAN

What is LocalDB

Connection String for LocalDB

connect to the automatic instance owned by the current user (in visual studio) by using the connection string
appsettings.json

{
  "ConnectionStrings": {
    "FooDB": "Server=(localdb)\\mssqllocaldb;Database=FooDB;Trusted_Connection=True;"
  },
}

Generate .mdf file

Code First

Open Package Manager Console (View > Other Windows > Package Manager Console)

Add-Migration <migrationName>

Update-Database

If everything goes well, FooDB.mdf will be created in you user folder (Users/foouser)

Database First

Using .mdf file

Create AppData folder in Project Folder and put .mdf in AppData

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=EmployeeDB;AttachDbFileName=%CONTENTROOTPATH%\\AppData\\EmployeeDB.mdf;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}

See: using-dbcontext-with-dependency-injection