EF Core 2.0.1 - Entity framework migration specific update - minus out initial database update

Wow, this title is pretty long.

Let's say you already have an existing database and right now you wanted to use EF Core to help migrate specific DML updates to your target database - which could be creating a new View or creating additional table minus out the initial database structure.

Note : Sometimes when you do an upgrade, you might get error message saying "your database has already been updated".

All rite, to be honest, you ca't do specific migration, example you can say "apply ABC Migration".

It is all based on the migration class that you've setup in your project,  meaning you get to type "Update-Database" without any parameter.

Anyways, please setup your project and all in the required EF nugets.

Next create the following class.

Then you specific what needs to be done. In this case, we are creating a view called "AppTesrtView".

Goto "package manager console" and then run "Update-Database". Please note y…

EF core hosting database migration on a separate project.

Project is available on Github.

Create a NEW project and then ensure you have installed all the nuget packages. The next important task that you need to do is to add a reference to your DbContext entities, if you have it separately from the main project

In your Startup.cs please ensure you have the following codes (which links directly to "Alphacert.Acc.Ods.Entities.Migrations".

services.AddDbContextPool(o => o.UseSqlServer(connectionString, x => x.MigrationsAssembly("Alphacert.Acc.Ods.Entities.Migrations")))

Using MsgPack in your core webapi

MsgPack (here) is reportedly faster then msgpack-cli in terms of performance. To get your excited, check out the diagram below :-

Yes, it is ridiculously fast and beat protobuf in many ways. I was gonna put on my hardworking cap and write up some formatters but this way is easier to do :-

Client code 

Client side code to de-serialized it.


Install it through nuget using the following command :-

Install-Package WebApiContrib.Core.Formatter.MessagePack -Version 2.0.0

Next, you gotta decorate your objects with the correct attributes.

And then somewhere in your controller, you can serialize your object as bytes and push it through using code below :-

Anaconda3 - Getting the environment installation of your library packages

How do you get the path where all your "pip install" packages are stored?

Fire up your python shell and run the following command :-

import os; print(os.path.dirname(os.__file__) + '/site-packages')

For me, i get the following output :-


Where CNTK is my current active environment and all the goodies that comes with it.

EF core using views

To access database view using DbContext, you just need to :

1. POCO - Create your POCO using code shown below. Please note that you need to match exactly the POCO to your views but not necessary all the fields. Let's say you have 10 fields but you can just defined 3 that is of interest to you :

2. Add your DbSet - You need to open up your DBContext and add in your DbSet Manually.

  public virtual DbSet VwValuations { get; set; }

3.OnModelCreating - in your DbContext, add your valuations data as shown below :

The data type used depends on your view.

That should be all the changes you need to make.

Cannot access a disposed object in ASP.NET Core working with DbContext

Bump into this error and found out the reason you cannot spin up a task to run a injected DbContext which normally injected by WebAPI dependency injection of a DbContext.


Create your dbcontext manually using code below (instead of using DbContext passed in the controller)

WebAPI support for File based Partial Content 206

Image core support for partial content is far out easier than i imagine. For example, if your application delivering a huge file, 100 Megabytes for example. then you might want to request these data as chunks

Some notes : this only works for File result and not with JSON which might fetch some data from the table. For example, you have a huge json (about 2M) and defining range 30-1000 will not change returned data.

Sample controller to handle partial content :- Yeap this is all you need.

Next, fire up your post and and you can see some of the results that i'm getting. Oh before anything else, please ensure you place a large txt file a folder.

As you can see from Postman. i create a request with Range : 30 - 1000 and the response is shown here too.

A couple of things to notice :-

Return result is 206. (Http Partial Content) 

Content-Length is 2500 ( which is the total file size we have) 

EF Net Core does not support nvarchar

I got this problem earlier today and i could swore it only happens for .net core 2.0. The message looks something like this :-

Data type 'nvarchar' is not supported in this form" after scaffolding from database 

After my model is binded or built, it throws this exception. I change

entity.Property(e => e.Comments).HasColumnName("Comments").HasColumnType("nvarchar");// No size specifier to


What is CNTK dynamic axis?

CNTK has static and dynamic axis. Static axis remains the same throughout the whole life cycle of the model. Dynamic axis has the following characteristics :-

a) varies from instance to instance
b) typically unknown
c) maybe ordered.

Sounds like a minibatch

Taken directly from Microsoft website :-

To make this more concrete, let’s consider two examples. First, let’s see how a minibatch of short video clips is represented in CNTK. Suppose that the video clips are all 640x480 in resolution and they are shot in color which is typically encoded with three channels. This means that our minibatch has three static axes of length 640, 480, and 3 respectively. It also has two dynamic axes: the length of the video and the minibatch axis. So a minibatch of 16 videos each of which is 240 frames long would be represented as a 16 x 240 x 3 x 640 x 480 tensor.

Dynamic axis in this case are video length (240 frames) and a total of 16 videos.

kubernetes dashbboard

Kubernetes dashboard is a UI driven approach to view and get us working with Kubernetes fasters.

Accessing the dashboard run :-

kubectl proxy

And you might get : Starting to serve on

So browse to : localhost:8001/ui

The nice dashboard of Kubernetes appears.

That's it.

kubernetes working with deployments : quick and easy

Do your deployment 

kubectl run connectcd --image=kepung/dotnetapp-prod --port=5050

Check your deployment is deployed 

kubectl get deployments

Get the pods spin up by your deployments and look for the labels :-

kubectl describe deployment/connectcd

kubectl get pods -l run=connectcd

NAME                         READY     STATUS    RESTARTS   AGE
connectcd-545c87f8d8-j4fsv   1/1       Running   0          27s

connectcd-545c87f8d8-j4fsv is our pods

Get all the pods in all namespace

kubectl get pods --all-namespaces

elastic search docker image that works

It has been challenging to find the images that works for ELK stack. Finally settle with the following images from elastic co version 6.2.2

Elastic Search

run the following image to get elastic search

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node"

Then browse to the following site :-



Kubernetes 101 - Basic stuff

When working with Kubernetes there are a few stuff that we need to be aware of,

1. images are often download from registry that lies somewhere in the cloud

2. kubernetes are organized into namespace. "default" namespace is the default. If you type kubectl get pods, you will get pods listed under this namespace by default.

webapi versioning the easy way

Turn out that doing webapi service versioning is relatively easy in core. First off, please install the following nuget package :-

Install-Package Microsoft.AspNetCore.Mvc.Versioning -Version 2.0.0

Next up, is to organize your controllers into folders. I prefer to use folder (namespace) as a way to do it, so i can have the same controller name versioned differently, as shown below :-

--->V1-->Controller-->HelloController(version 1)

-->V2 -->Controller-->HelloController (version 2)

Next we just need to decorate our HelloController with the proper attribute.

Version 1 Controller.

Version 2 Controller

webapi logging - log level

Just to clarify, if you set log level to Debug ( LogLevel = 1) then your logging will shows any log above it.

Here is the definition for log level,

 Trace = 0,
 Debug = 1,
 Information = 2,
 Warning = 3,
 Error = 4,
 Critical = 5,
 None = 6

Given we define LogLevel = Debug, any logs value bigger than 1 will appear.
If you want to scale down details of your logging, try setting your log level higher to Warning, for example.

You might want to change your logging method call too.

CNTK - Simple linear regression

The following are sample code to create a linear regression to work with car data.

CNTK : Different mini-batch size detected

Size of your test data and train data differs. Try making it the same before running your code again.