Wednesday, April 29, 2015

Register to attend the Microsoft MVP Virtual Conference

Hi All – I wanted to let you know about a great free event that Microsoft and the MVPs are putting on, May 14th & 15th.  Join Microsoft MVPs from the Americas’ region as they share their knowledge and real-world expertise during a free event, the MVP Virtual Conference.

The MVP Virtual Conference will showcase 95 sessions of content for IT Pros, Developers and Consumer experts designed to help you navigate life in a mobile-first, cloud-first world.  Microsoft’s Corporate Vice President of Developer Platform, Steve Guggenheimer, will be on hand to deliver the opening Key Note Address.

Why attend MVP V-Conf? The conference will have 5 tracks, IT Pro English, Dev English, Consumer English, Portuguese mixed sessions & Spanish mixed sessions, there is something for everyone! Learn from the best and brightest MVPs in the tech world today and develop some great skills!

Be sure to register quickly to hold your spot and tell your friends & colleagues.

The conference will be widely covered on social media, you can join the conversation by following @MVPAward and using the hashtag #MVPvConf.

Register now and feel the power of community!
Register
Register
Happy Coding.

Regards,
Jaliya

Monday, April 27, 2015

Installing Ubuntu 14.04.2 LTS (Desktop x64) on Hyper-V and Configure it to Connect to Internet

I had a really hard time installing Ubuntu 14.04.2 LTS (Desktop x64) on Hyper-V and configuring it to connect to Internet. Of course the installation was smooth, but configuring the Ubuntu to have Internet was a disaster for me. Have read many articles, tried different scenarios and got myself into a mess  with multiple virtual Internal and External switches. Started to hate Hyper-V, but apparently, things went well.

And this is a step by step guide for you to start from scratch. Please not that, I am not going to go in detail about creating a virtual machine on Hyper-V.

I will be explaining the process with External and Internal virtual switches.

External Virtual Switch

My environment is Windows 8.1 with a working Wi-Fi connection. No previously created Internal or External virtual switches.

The version of Ubuntu I am going to install on Hyper-V is, Ubuntu 14.04.2 LTS (Desktop x64).

In New Virtual Machine wizard, in Configure Networking, I am selecting Not Connected.

9
New Virtual Machine Wizard
2
Installation Summary
Now do the installation, in the middle of installation, you can see that you don’t have internet. That’s of course obvious.

5
Not connected to Internet
Once installed, for worse case, shut down the newly created Ubuntu virtual machine. (You actually don’t have to shut it down and you still can move ahead with below, but let’s just shut it down.)

In Hyper-V click on Virtual Switch Manager.

image
Virtual Switch Manager
There, create a new External virtual network switch.

8
New External Virtual Switch
In the next step, give a name, I am using External Virtual Switch, and I am selecting my Wi-Fi adapter to be used in virtual switch and allowing sharing as below.

6
External Virtual Switch Properties
Click on Apply and Ok.
10
Network Connections
Once it got created, Right click on vEthernet (External Virtual Switch) connection, click on Properties, go to Sharing tab. Please note that I am not doing any changes here, and I am keeping it as it is. In some articles, they say that you need to tick the checkboxes and do the allowing. There is a scenario, which you really need to enable these, and I am describing that later in the post. Hang on!. So for now, I am keeping this as it is.

15
vEthernet (External Virtual Switch) Sharing
Right click on Ubuntu Virtual Machine and click on Settings. It will look like below.

11
Virtual Machine Settings
Now set the Virtual Switch property to created External Virtual Switch.

12
Virtual Machine Settings
Click on Apply and Ok.

Now start the Ubuntu virtual machine back again and now you should have internet.

Now let’s see what are the Wired Connection properties in your Ubuntu machine. You should be seeing the following. In IPv4 Settings tab, Method is Automatic(DHCP).

17
Wired Connection IPv4 Settings
And when you check Connection Information for Wired Connection, you can see that a IP address is assigned, and the Gateway(Route) and DNS is assigned with your routers settings.

14
Wired Connection Information
Now let’s say, you still don’t have internet for some reason. Here is a workaround.

First go to vEthernet (External Virtual Switch) properties and do the allowing as below.

7
vEthernet (External Virtual Switch) Sharing
Run a ipconfig on command prompt and get the vEthernet (External Virtual Switch) values.

18
ipconfig
In Ubuntu machine, let’s manually configure the IPv4 settings as follows. And of course, you need to replace these with yours.

16
Wired Connection IPv4 Settings
Gateway is the IPv4 address of vEthernet (External Virtual Switch) or you can use the Default Gateway of vEthernet (External Virtual Switch). When you use the IPv4 address of vEthernet (External Virtual Switch), that means you are going out through vEthernet (External Virtual Switch), so you should do the allow sharing on vEthernet (External Virtual Switch) connection. When you use the Default Gateway of vEthernet (External Virtual Switch), that means you are going out through the router and not using the vEthernet (External Virtual Switch). And then of course, you don’t have to do the allow sharing on vEthernet (External Virtual Switch) connection on Windows. So the rule here is, if you are going to use the IPv4 address of vEthernet (External Virtual Switch) as your Gateway here, you need to do the allow sharing on vEthernet (External Virtual Switch) connection on Windows. Here since, I have done the allowing, I am using the IPv4 address of vEthernet (External Virtual Switch) as the Gateway.

For DNS, I am setting as 8.8.8.8 or it can be the same as the DNS of vEthernet (External Virtual Switch) which is 192.168.0.254 in my scenario.

13
Wired Connection Information
So, that’s it. Now you should have Internet.

Internal Virtual Switch

So this is how you can configure the Ubuntu virtual machine with a Internal switch. For this you will have to shutdown the Ubuntu virtual machine and do the following.

Create a new Internal Virtual Switch in Hyper-V. I am naming it as Internal Virtual Switch.

1
New Internal Virtual Switch
Click on Apply and OK.

Open up properties of vEthernet (External Virtual Switch) and do the allow sharing with newly created vEthernet (Internal Virtual Switch).

5
vEthernet (External Virtual Switch) Properties
Open up the properties of vEthernet (Internal Virtual Switch) and inside Internet Protocol Version 4 (TCP/IPv4), make sure the IP Address to look something like below. When I allow sharing of vEthernet (External Virtual Switch) with newly created vEthernet (Internal Virtual Switch), for me the default IP Address of vEthernet (Internal Virtual Switch) was in a different network range. So I have changed it as follows.

3
vEthernet (Internal Virtual Switch) TCP/IPv4 Settings
Change your Ubuntu virtual machines' Network Adapter to Internal Virtual Switch.

2
Ubuntu Virtual Machine Network Adapter
Switch on the Ubuntu virtual machine. Make you’re your connection properties look like below. If Automatic(DHCP) doesn’t give like below, you will have to assign IPv4 Settings manually. For me it was not, so I am in the Manual mode.

4
Wired Connection Properties
Give an IP address, and here the Gateway should be the IP Address of vEthernet (Internal Virtual Switch). DNS Servers can be either, public DNS which is 8.8.8.8 or the IP Address of vEthernet (Internal Virtual Switch) which is 192.168.0.100 for me. So my wired connection summary is like below.

6
Wired Connection Information
Now you should have Internet.

Please note that, sometimes, you will need to disconnect and reconnect the Wired Connection for changes to be effected. Once you got the concept, it’s possible for you to rearrange the above steps to match your need. And of course, rather than starting fresh with no previous Internal/External switches created,  you can start the whole process with previously created Internal/External switches.

Last note, Hyper-V rocks!

Your comments are mostly welcome.

Happy Coding.

Regards,
Jaliya

Saturday, April 25, 2015

Session : A Lap Around with Azure Websites at Global Azure Bootcamp, Sri Lanka - 25th April, 2015

Whilst Global Azure Bootcamp were happening all around the world on Saturday, April 25, 2015, set of Sri Lankan MVPs’ has organized Global Azure Bootcamp on Colombo, Sri Lanka as well. Microsoft had a total of 183 confirmed event locations for Global Azure Bootcamp, 2015.

Following is the list of speakers who delivered their sessions on the Sri Lanka’s Global Azure Bootcamp.

SNAGHTML44ccd4c
List of Speakers
I was privileged enough to deliver a session there along with one of Sri Lanka’s most senior MVPs Fiqri Ismail. Fiqri is a MVP in ASP.NET/IIS for 9 consecutive years.

Fiqri has started off with the session giving an introduction to Azure websites, and after giving an introduction, I have demoed how we can publish an ASP.NET application to Azure using Visual Studio. Then showed how we can create a Azure web site using Azure current portal and how we can integrate it with GitHub. Fiqri wrapped up the session, explaining different Azure Web Stacks and demoing how to access Visual Studio Online “Monaco” from the new Azure Portal .

2015-04-29_9-06-05
A Lap Around with Azure Websites
Happy Coding.

Regards,
Jaliya

Friday, April 24, 2015

I am in the List of Top 20 TechNet Guru Award Winners

Just now got to know that, as of today, I am included in the list of Top 20 TechNet Guru Award Winners. What else can I say, feeling great!
Top 20 TechNet Guru Award Winners
Read the original post on,
http://blogs.technet.com/b/wikininjas/archive/2015/04/24/who-are-the-top-20-technet-guru-award-winners.aspx

Happy Coding.

Regards,
Jaliya

Saturday, April 18, 2015

Visual C# Technical Guru - March 2015

Another month as a judge in Microsoft TechNet Guru Awards under Visual C# category.

The TechNet Guru Awards celebrate the technical articles on Microsoft TechNet.

Post in WikiNinjas Official Blog,
image
Visual C# Technical Guru - March 2015
Happy Coding.

Regards,
Jaliya

Sunday, April 5, 2015

What is .NET Core

We have been using .NET framework since 2002 (.NET Framework 1.0) which was released along with Visual Studio 2002. It has amazingly evolved over time and as of today, we are in the age of .NET 4.6 Preview which was initially released with Visual Studio 2015 Preview. Last November, being specific, 12th November 2014, along with the .NET 4.6, Microsoft has announced another framework which is .NET Core.

So what’s this .NET Core? Let’s find out.

If you have a look at the following picture, you should be able to get a basic understanding of how .NET framework is structured.
3173.Pic1
Overview of .NET Framework
The .NET framework is a collection of set of verticals such as Windows Desktop, Windows Store, Windows Phone, ASP.NET 4 etc. and for each these verticals there are different Base Class Libraries (BCL) and runtimes (for Windows Desktop and ASP.NET 4, basically it’s the same framework and runtime). Some libraries are available in one vertical and those same libraries are not available in other. Best example for this scenario would be Windows Store and Windows Phone. Isn't it great if we can have a single Base Class Library, that can be used across every vertical/application model regardless of the application model and the operating system that the application runs upon.

And that’s where the .NET Core comes in.
image
Overview of .NETCore
In simple, .NET Core is a framework which includes all the core and primary libraries which is available in all the different Base Class Libraries in .NET full framework. So with .NET Core there will be no different Base Class Libraries, there will be only one unified BCL which can be used in Windows Desktop, Windows Store etc. application models and most importantly it can run on Windows, OS X and Linux. Here there is a runtime adoption layer, that’s because for Windows 10 Universal apps, the runtime will be .NET Native and for ASP.NET 5 on .NET Core, the runtime will be Core CLR.

Another things is, the .NET Framework is a machine-wide framework. Any changes made to it affect all applications taking a dependency on it. If you upgrade the .NET Framework version in your machine, there is no 100% guarantee that applications which targets the old frameworks still works.

.NET Core answers this question by giving the ability to be shipped via NuGet. That means you can ship a private version of the .NET Core Framework with your app. Other apps' versions can't change your app's behavior. Here the nice thing is, the entire .NET Core platform is not distributed as a single NuGet package. Instead, it’s a set of fine grained NuGet packages. In simple with the .NET Core, you are building your own framework.

Now let’s see .NET Core in action. For that, let’s create an ASP.NET web application using Visual Studio 2015.

When you try to create a ASP.NET application using Visual Studio 2015 targeting .NET Framework 4.5 or above, you will see following project templates.
image
New Project
Let’s move forward selecting an ASP.NET Web Application and  you will be thrown with the following dialog. There let’s choose ASP.NET 5 Empty and click on OK.
image
New ASP.NET Project
Once we do that, a new ASP.NET Web Application will be created and it is slightly different to ASP.NET 4 or below Web Application project templates. There is no longer a web.config file, instead there is a project.json file. Under the solution explorer if you  expand the References node, there you will see the following.
image
ASP.NET 5.0 and ASP.NET Core 5.0
There you should be able to see ASP.NET 5.0 and ASP.NET Core 5.0. In here basically ASP.NET 5.0 will be running on top of .NET Framework 4.5 and ASP.NET Core 5.0 will be running on top of .NET Core 5.

For more information on .NET Core,
Happy Coding.

Regards,
Jaliya

Thursday, April 2, 2015

Wrote a post on Wiki Life at Official Blog of TechNet Wiki

Got the pleasure of writing a post in Wiki Ninjas - Official Blog of TechNet Wiki. The title of the post was Wiki Life: Porting Blog Posts as TechNet Wiki's and Vice Versa.

image
Wiki Life: Porting Blog Posts as TechNet Wiki's and Vice Versa
Read the rest on,
Happy Coding.

Regards,
Jaliya

Wednesday, April 1, 2015

Use of InversePropertyAttribute in Entity Framework

InversePropertyAttribute in System.ComponentModel.DataAnnotations.Schema can be quite handy when using Entity Framework code first. Let’s take the following scenario.

Consider that you have the following two entities and the data context.
public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual Hobby PrimaryHobby { get; set; }
    public virtual Hobby SecondaryHobby { get; set; }
}
 
public class Hobby
{
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual List<Person> People { get; set; }
}
 
public class MyDbContext : DbContext
{
    public DbSet<Person> People { get; set; }
    public DbSet<Hobby> Hobbies { get; set; }
}
When a database is created from the above model, you will be getting a database like below.

image
Database
There is nothing wrong with this model. Since we have exposed “People” property of type List<Person> in the “Hobby” entity, Entity Framework is creating a foreign key inside “Person” entity named “Hobby_Id” along with the foreign keys “PrimaryHobby_Id” and “SecondaryHobby_Id”.

But what if this is not what you want. Instead, Let’s say when you want to get all the people having a specific hobby, you only want to get the people in who’s primary hobby is that particular hobby. For that there should be a relationship between “People” property in “Hobby” entity and “PrimaryHobby” property in “Person” entity. And that’s where the InversePropertyAttribute comes in.

Now let’s modify the “Person” entity decorating the “PrimaryHobby” property with the InversePropertyAttribute.
public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    [InverseProperty("People")]
    public virtual Hobby PrimaryHobby { get; set; }
    public virtual Hobby SecondaryHobby { get; set; }
}
With that change, the underlined database get changed as follows.

image
Database
There is no “Hobby_Id” property anymore, the navigation from “Hobby” to “People” will be done through “PrimaryHobby_Id”.

The same thing can be done through Entity Framework Fluent API.
public class MyDbContext : DbContext
{
    public DbSet<Person> People { get; set; }
    public DbSet<Hobby> Hobbies { get; set; }
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Person>()
            .HasOptional(a => a.PrimaryHobby)
            .WithMany(b => b.People);
    }
}
So that’s it. Please find the code sample in my OneDrive.


Happy Coding.

Regards,
Jaliya