Web API With Visual Studio part-2

Kajasumanie Kanapathipillai
3 min readFeb 28, 2018

part-1 link:

https://medium.com/@kkajasu/web-api-with-visual-studio-8373ca61b611

by part 1 you we create inmemorydatabase ,now i am going to create a database in sqlserver so i need configuration .

  • * why need configration??
  • configration is help to connect the DbContext with SqlServer.when we are using config we get the connectionstring from json file.the json file indicate the sqlserver connection details.for example in the startup file

services.AddDbContext<DetailContext>(opt => opt.UseSqlServer(config.GetConnectionString(“DefaultConnection”)));

In the json file=>

{

“ConnectionStrings”: {

DefaultConnection”: “Server=(localdb)\\MSSQLLocalDB;Database=DetailsDEMO;Trusted_Connection=True;MultipleActiveResultSets=true”

},

1-Adding configuration

I move my model file in a data folder,this is really no need

Go to your startup.cs file then rewrite the code like this

public class Startup{private readonly IConfiguration config;public Startup(IConfiguration config)

--

--

No responses yet