Code First Migration – ASP.NET MVC 5 With EntityFrameWork & MySql


We know how to use Code First Migration in SQL Server. But in most cases, a customer will think we can use it for the open source database. So that’s the reason we pick the “MySQL” database, and we can follow the same steps we follow in the “SQL” database. In this article, we are going to explain Code First Migration in ASP.NET MVC 5 with Entity FrameWork & MySQL.


  1. MySQL Installer
  2. Download MySQL Workbench
  3. Visual Studio ( We are using Visual Studio 2017 Community Edition ).

Create a Web Application using MVC 5

Click on File -> New -> Project -> Visual C# -> Web -> ASP.Net Web Application ( .Net Framework ).

Click on “OK” then click on “MVC”.

Install EntityFramework & MySql Entity

Go to Visual Studio “Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution” or Right click on your Web Application then click on “Manage Nuget Packages”.


Search EntityFramework in the “Browse” Section.


Search MySql.Data.Entity in the “Browse” Section.

Once we installed EntityFramework & MySql Entity in our application then it will generate a SQL and MySQL Provider inside the EntityFramework Section in Web.Config.

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>

Model Class

We just created a sample model class for demo purpose.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebAppWithMySql.Models
public class Student
public int Id { get; set; }

public string Name { get; set; }

public string Password { get; set; }

Creation of DBContext

Create a db context class in our application. The following dbcontext will point out our connection string in WebConfig.

using MySql.Data.Entity;
using System.Data.Entity;
using WebAppWithMySql.Models;

namespace WebAppWithMySql
public class WebAppContext : DbContext
public DbSet<Student> Products
public WebAppContext()
//Reference the name of your connection string ( WebAppCon )
: base("WebAppCon") { }

Connection String

We added the same connection string name that we added in the dbcontext class. The following connection string represents “MySql” Db.

<add name="WebAppCon" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;userid=root;password=rajeesh123;database=WebAppMySql;persistsecurityinfo=True" />

Migration Steps

  1. Enable-Migrations – ( We need to enable the migration, only then can we do the EF Code First Migration ).
  2. Add-Migration IntialDb (migration name) – ( Add a migration name and run the command ).
  3. Update-Database -Verbose — if it is successful then we can see this message (Running Seed method).

Once Migration is done; then, we can see that the respective files are auto-generated under the “Migrations” folder.


See Also

You can download other ASP.NET Core source codes from MSDN Code, using the link, mentioned below.


In this article, we are going to explain Code First Migration in ASP.NET MVC 5 with EntityFrameWork & MySql. I hope this article is useful for all Azure beginners.


Send Email Using ASP.NET Core 1.1 With MailKit In Visual Studio 2017


We are familiar with Sending Email Using Asp.Net With C#. But today, we are going to teach you how to send email using ASP.NET Core 1.1 with MailKit. We can implement it in ASP.Net Core very easily as compared to the previous versions of ASP.NET.

Before reading this article, you must read the articles given below for ASP.NET Core knowledge.


MailKit is a cross-platform mail client library built on top of MimeKit. That means we get all the mail sending libraries from MailKit, such as – Simple Mail Transfer Protocol (SMTP) etc.

Simple Mail Transfer Protocol (SMTP)

Simple Mail Transfer Protocol (SMTP) is a TCP/IP protocol used in sending and receiving e-mail. Most e-mail systems that send mail over the Internet use SMTP to send messages from one server to another.The messages can then be retrieved with an e-mail client using either POP or IMAP.

The following is a list of SMTP Server and Port Numbers.

Sl.No Mail Server SMTP Server( Host ) Port Number
1 Gmail 587
2 Outlook 587
3 Yahoo Mail 465
4 Yahoo Mail Plus 465
5 Hotmail 465
6 587
7 zoho Mail 465

Assemblies Required

The following assemblies are required for sending email using ASP.NET Core with MailKit.

using MailKit.Net.Smtp;
using MimeKit;

Adding MailKit in Our Project

Go to “Tools -> NuGet Package Manager -> Manage Nuget Package for Solutions…” Then, search “MailKit”, Choose and Install the latest version “V1.12.0” in your application.

MailKit Installation

MailKit Installation

Project Structure

New .NET Core tooling is available in Visual Studio 2017 by default. In the Dependencies folder, every package tool has separate folder like MailKit saved into NuGet folder. If you have a client side tool like bower, then its dependencies are saved into it’s folder.

Project Structure ASP.NET Core 1.1

Project Structure ASP.NET Core 1.1


The following code contains the mail sending code of ASP.NET Core.

using MailKit.Net.Smtp;
using MimeKit;
using System;

namespace EmailApplication
    class Program
        static void Main(string[] args)
                //From Address
                string FromAddress = "From Email Address";
                string FromAdressTitle = "Email from ASP.NET Core 1.1";
                //To Address
                string ToAddress = "To Email Address";
                string ToAdressTitle = "Microsoft ASP.NET Core";
                string Subject = "Hello World - Sending email using ASP.NET Core 1.1";
                string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks ( Windows, Linux, Mac ) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end.";

                //Smtp Server
                string SmtpServer = "";
                //Smtp Port Number
                int SmtpPortNumber = 587;

                var mimeMessage = new MimeMessage();
                mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
                mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
                mimeMessage.Subject = Subject;
                mimeMessage.Body = new TextPart("plain")
                    Text = BodyContent


                using (var client = new SmtpClient())

                    client.Connect(SmtpServer, SmtpPortNumber, false);
                    // Note: only needed if the SMTP server requires authentication
                    // Error 5.5.1 Authentication 
                    client.Authenticate("From Address Email", "Password");
                    Console.WriteLine("The mail has been sent successfully !!");

            catch (Exception ex)
                throw ex;

Important Points

  • When you are sending mail with your “gmail” account, enable less secure apps so that you will be able to login from all apps. Otherwise, it will throw authentication error like 5.5.1 authentication.
  • Remove 2-Step Verification.

In the following code, we can mention username for “gmail” account but in other service like “hotmail”, we must provide the full email address because other Microsoft accounts, like Outlook, live, etc. have the same SMTP Server Address “”.

client.Authenticate("From Address Email", "Password");


In previous version, ASP.NET Core 1.0 contained all the versions & dependencies in project.json file but in new version, i.e., ASP.NET Core 1.1, they are saved in csproj.

<Project Sdk="Microsoft.NET.Sdk">


    <PackageReference Include="MailKit" Version="1.12.0" />





We learned how to send email using ASP.NET Core 1.1 with MailKit in Visual Studio 2017. I hope, you liked this article. Please share your valuable suggestions and feedback.

Visual Studio 2017 : New Features & Installation


Feeling great & Looking Smart. I know every one is excited for the new release of “Visual Studio 2017”. Yes , Microsoft Visual Studio celebrated it’s 20th years of glory with all tech lovers in the world love it. Now, it has come up with lots of excitement. Thus, I am happy to share the important features of Visual Studio 2017 with all the tech lovers.

Visual Studio 2017 System Requirements

The following are the minimum requirements of Visual Studio 2017 installation.

Download Visual Studio 2017

Go to this link Visual Studio 2017 , choose & download your favorite edition.

Installing Visual Studio 2017

Visual Studio 2017 Installation Window shows 3 sections.

  1. Workloads
  2. Individual components
  3. Language packs


We can choose the appropriate development section from Visual Studio Workloads. I selected “ASP.NET and Web development & .NET Core cross-platform development”. It also contains around 5.50 GB. Thus, If you select all Workloads, then it will reach 50 GB+.

Individual components

We can choose the required component from this section.

Language packs

We can use different languages in Visual Studio. Thus, we can choose the appropriate language in this section.

Installation Process

We are going to install Visual Studio Community 2017 edition in our machine. Ones the following process is complete, we can launch & access the new features in Visual Studio 2017.

Features in Visual Studio 2017

The following are the new features in Visual Studio 2017.

Live Unit Testing

This feature is only available in Visual Studio 2017 Enterprise edition. Without running the solution, we can easily test the Application because few hidden background process happens in our Application through “Live Unit Testing”. We can enable Live Unit Testing for which you need to go to the “Test” command of the top-level menu bar in VS, choose “Live Unit Testing”, then “Start”.

Image Credit : Channel 9 Visual Studio 2017 Lanuch

Image Credit : Channel 9 Visual Studio 2017 Lanuch

We noticed that 3 symbols appeared in our code due to running on background Live Testing.

  • Cross Sign – line of executable code. The test is covered and it indicates that a failure test.
  • Tick Mark – line of executable code. The test is covered and it indicates that a success test.
  • Minus – line of executable code. Not yet covered a single Test.

Dotted Line

The is a very cool feature in Visual Studio 2017 because this option helps to identify the exact open and close curly braces “{}” through dotted line in our code. This dotted line is really helpful for when you are working on a bulk amount of code in a single page.

Filttered IntelliSense Search

The new Filtering IntelliSense Search option is available in Visual Studio 2017. This option is one of the powerful way to consume the search time in our code. The following IntelliSense bottom tray contains icons as Properties, Interface, Modules, Namespaces, Enums, Classes, Constants etc. For example, if i want to search an Interface, then I can choose an Interface Icon from the bottom of the tray, else it will show all the possible contents in our solution.

Improvements Of Navigation Controls

  1. Go to All ( Cntrl + T )
  2. Go to Line ( Cntrl + G )
  3. Go to File ( Cntrl + 1 + F )
  4. Go to Type ( Cntrl + 1 + T )
  5. Go to Member ( Cntrl + 1 + M )
  6. Go to Symbol ( Cntrl + 1 + S )

Go to All ( Cntrl + T )

Press “Cntrl + T”, then it will display one tray above the search bar. Thus, we can search the content with the help of the options given below like Line/Files/Types/Members/Symbols. For example, I want to search type in our entire solution or an Application. Now, choose “Type” Icon in the tray and type in the search bar, so it will filter and show the exact results as much as faster than the earlier versions of VS. The shortcut is “Cntrl + 1 + T”.

Find All Reference ( Shift + F12 )

We can find all the references in our entire solution. The highlighted one is all the reference results by a combination of project, definition and path.

Code Suggestions

This is a very exciting feature in VS2017. It gives us the good code practice in our Application. The code given below notices that we have written an “If” condition without curl braces. Thus, it gives us the suggestion tp add the curl braces to understand the code.

Code Style Changing

We can change the code style option in our VS2017. Go to “Tools -> Options -> Text Editor -> Basic -> Code Style -> Naming”.



We learnt installation & new features of Visual Studio 2017. I hope, you liked this article. Please share your valuable suggestions and feedback.

%d bloggers like this: