Posts

Showing posts from January, 2018

Work with EntityFrameworkCore and asp.net core

Image
1. Select Required EntityFrameworkCORE  Package When you search on the EntityFrameworkCore in Nuget Package Manager you will get 100+ packages... All the packages are derived from Microsoft.EntityFrameworkCore 2. You need to select Required package  Then it will add the Dependencies 3. I am going to work with SqlServer and i am going to add  Microsoft.EntityFrameworkCore.SqlServer 4. Now Create the DataBaseContext class and here i am going to create MyDataBaseContext class  and extend DBContext 5. Put the DataBase Configuration you need to Override OnConfiguring Method protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {   optionsBuilder.UseSqlServer(@"Data Source=.;Initial Catalog=testdb;Integrated Security=True;"); } Then you need to configure OptionBuilder method to say UseSqlServer and give the connection link to the DataBase What you Need to Know - If Core performing Dat...

How to Set Default path for the Asp.Net Core Web Api

Image
If you want to learn about How to set up Swagger in .Net core web api please follow this link 1. Go To Project Properties > Open LaunchSettings.json 2. Select Your Running Profile I am running on 'IIS Express' profile 3. Change the "LaunchUrl" property into url you need to set as default path I need to set my Default path as swagger document and i change it to "swagger/" , 4. Now its time to run the application

How to configure swagger in .Net core (asp.net core) webapi

Image
1. Assumption - You have started the Asp.net core web API project 2. Now you need to add Swagger asp.net core package using Package Manager Console Install-Package Swashbuckle.AspNetCore Using Nuget Package Manager  3. Now You need to configure Swagger Manually, Like Asp.net web api this one does not generate Swagger Configuration class 4. Open Startup.cs class in your project 5. Goto ConfigureServices function and add Swagger Configuration details services.AddSwaggerGen(c => {       c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); We use this to add swagger service to the container  6. Goto Configure function and add Swagger runner details app.UseSwagger(); app.UseSwaggerUI(c => {       c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); This function is to provide run time configuration  7. Now Your ready to run