Entity Framework Core: Initialize and Create Database

When you have finished defining your EF model the first time and you want to create the actual database and tables. First you will need to install the EF Core command line tools, you can do this in the .NET Core CLI or inside Visual Studio. But this post I will be focusing on Visual Studio only. So open your Package Manager Console and enter the following commands.

Install-Package Microsoft.EntityFrameworkCore.Tools

The Install-Package command will install the command tools for you, before you can continue to the next command.

Add-Migration InitialCreate

Add-Migration command will create the migration to generate the initial sets of tables for the model.

Update-Database

Update-Database command will create the database and applies the new migration to it.

C#: DataTable to CSV

 

Recently I wrote a small program to allow me to connect to a SQL database and export a selected table to a CSV file. So I needed a method that can take in a DataTable and the delimiter character to use. The returned result is a string which can be save straight to a text file.

Below is the method in my program, you may copy, modify and use it in your own program.

I use a StringBuilder class to build my lines of comma separated values and then return it as a String type. Currently the code only format string values with double quotes inserted around the value and the rest is a straight output.

(more…)

Shares