Nov 30, 2015

What is the Difference between RANK() and DENSE_RANK() in SQL Server?

Rank()

Rank function will generates a unique number to each distinct row, but it leaves a gap between the groups.

Dense_Rank()

Dense_Rank function is similar to Rank with only difference, this will not leave gaps between groups.
DECLARE @Table TABLE (
      column varchar(2)
)

INSERT INTO @Table (column)
      VALUES ('A'),('A'),('A'),('B'),('B'),('C'),('C');

SELECT
      Col_Value,
      Rank() OVER (ORDER BY column) AS 'Rank',
      DENSE_RANK() OVER (ORDER BY Col_Value) AS 'DENSE_RANK'
FROM
      @Table;

Column RANK DENSE_RANK
A 1 1
A 1 1
A 1 1
B 4 2
B 4 2
C 6 3
C 6 3

Nov 27, 2015

Difference between ToClone and ToCopy method in .Net

ToClone will copy the structure of a data where as ToCopy will copy the complete structure as well as data.
var strArr1 = new string[] { "1", "2", "3","4" }; 
var strArr2 = strArr1 ; //copy
var strArr3 = new string[] { "1", "2", "3","4" }; 
var strArr2 = strArr1.ToClone(); //Clone

Nov 19, 2015

Node.js has been released new stable version v5.1.0

Node.js has been release new stable version 5.1.0, couple of days ago.

Its a good news for Node.js lover that they got new stable release version 5.1.0 with bug fixes and few notable changes.

For more detail please visit official website of  Node.Js or Release page

Nov 17, 2015

JavaScript error SCRIPT1002: Syntax error

SCRIPT1002:Syntax error occurred most probably in Internet Explorer.

First we try to re-procedure the issue writing below code.

    
    


    Click Me!    

Yes, that is the problem. void is an operator, not a function.

Resolution
So instead of javascript:void(), write the # with href and try it. Hopefully it will work.

Nov 5, 2015

Asp.Net 5 and MVC 6 new features.

As I already Written blog for Asp.Net 5 and MVC  6 difference on my previous blog.

Here I am going  to little more explore about Asp.Net 5 and talking about new feature included in Asp.Net 5.

Listing  few features,
  1. Asp.Net on Cross-Platform 
  2. No More Web Forms
  3. Tag Helpers
  4. View Components
  5. Many Client side framework supported. (Gulp, NPM and Bower Support)
  6. Common Controllers for MVC and Web API
  7. AngularJS
  8. Inbuilt Dependency Injection Framework
  9. xUnit.net
1.  Asp.Net on Cross-Platform 
  • Asp.net 5 application run on cross-platforms like windows, OSX and Linux.
  • Developers and designers can start building apps with Asp.Net 5  because of no visual studio required.
  • So they can use their favorite IDE or development environments editors such as Sublime Text, Atom, Emacs and Brackets.
2. No More Web Forms 
  • Now, Its time to move forward for those who love Asp.Net Web Forms.
  • Because of Web Forms apps can not take advantage from new features of Asp.Net 5.
  • If you still want to continue buld Web forms apps in Visual Studio 2015 then need to targeting the .NET 4.6 framework.
3.  Tag Helpers
  • Biggest change on Asp.Net MVC application when you create your views.
  • Because of Tag Helpers are a better alternative of using traditional MVC helpers. 
Let's see following example of MVC view that contains a form of creating a new category.
@model FirstProject.Models.Categories

@using (Html.BeginForm())
{
    
@Html.LabelFor(m => p.Name, "Name:") @Html.TextBoxFor(m => p.Name)
}
  • In the above example of view, the Html.BeginForm(), Html.LabelFor() and Html.TextBoxFor() helpers are used to create the form. 
  • HTML Designer would not be familiar with above helpers. 
Now let's see the same example form using Tag Helpers.
@model FirstProject.Models.Categories
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"

  • Time to compare both the view and notice that using Tag Helpers, created form contains look like HTML elements. 
  • It meant form contains an Input element instead of Html.TextBoxFor() helper. So it would be fine HTML designer fine with this page.
  • Tag Helpers introduce one special asp-for attributes on html tag. These attributes are used to extend the elements with server side Asp.Net MVC functionality.
4. View Components 
  • Time to say Goodbye subcontrollers and adapt View Components.
  • If you remember, in previous versions of ASP.NET MVC, the Html.Action() helper is typically used to invoke a sub-controller. A sub-controller may display stuff like tag clouds, dynamic links, side bars or whatever.
  • ASP.NET MVC 6 introduced the new View Component to replace widgets that use Html.Action().
Lets create one a View Component that displays Simple text.
using Microsoft.AspNet.Mvc;
using System;
 
namespace Partials.Components
{
    public class TextPrint : ViewComponent
    {
        public IViewComponentResult Invoke()
        {   
            return View("_TextPrint", "Hello This is for test!");
        }
    }
}
Here how look like the _TextPrint partial.
@model string
 
@Model
Now, let see how we can usre the TextPrint View Compenent in MVC view.
@Component.Invoke("TextPrint")
  • View Components are very similar to subcontrollers. 
  • However, subcontrollers were always a little odd.  
  • They were pretending to be controller actions but they were not really controller actions.
5. Many Client side framework supported. (Gulp, NPM and Bower Support)
  • Front-end development gets a lot of love in Asp.Net 5 through its support for Gulp. 
  • GruntJS is a task runner that enables you to build front-end resources such as JavaScript and CSS files. For example, you can use GruntJS to concatenate and minify your JavaScript files whenever you perform a build in Visual Studio.
  • In order to support GruntJS, Microsoft needed to support two new package managers (beyond NuGet). First, because GruntJS plugins are distributed as NPM packages, Microsoft added support for NPM packages.
  • Second, because many client-side resources – such as Twitter Bootstrap, jQuery, Polymer, and AngularJS – are distributed through Bower, Microsoft added support for Bower.
  • This means that you can run GruntJS using plugins from NPM and client resources from Bower.
6. Common Controllers for MVC and Web API
  • In previous versions of ASP.NET MVC, MVC controllers were different than Web API controllers. An MVC controller used the System.Web.MVC.Controller base class and a Web API controller used the System.Web.Http.ApiController base class. 
  • In MVC 6, there is one and only one Controller class that is the base class for both MVC and Web API controllers. There is only the Microsoft.AspNet.Mvc.Controller class.
  • MVC 6 controllers return an IActionResult. When used as an MVC controller, the IActionResult might be a view. When used as a Web API controller, the IActionResult might be data (such as a list of products). The same controller might have actions that return both views and data.
  • In MVC 6, both MVC controllers and Web API controllers use the same routes. You can use either convention-based routes or attribute routes and they apply to all controllers in a project. 
7. AngularJS
  • Now a days AngularJs is most popular client-side frameworks for building SPAs (Single Page Applications).
  • So for fortunatly Visual Stdio 2015 includes templates for creating AngularJS modules, controllers, directives and factories.
  •  The support in ASP.NET 5 for Gulp makes ASP.NET an excellent server-side framework for building client-side AngularJS apps. 
  • You can combine and minify all of your AngularJS files automatically whenever you perform a build. 
  • You can interact with an MVC 6 controller from an AngularJS $resource using REST.
8. Inbuilt Dependency Injection Framework 
  • ASP.NET 5 has built-in support for Dependency Injection and the Service Locator pattern. This means that you no longer need to rely on third-party Dependency Injection frameworks such as Ninject or AutoFac.
  • Previously need do many things for Dependency Injection and Resolver but in Asp.Net 5 has built-in support.
  • In Asp.Net 5 you can use the [Activate] attribute to inject services via properties.
  • You can use [Activate] not just on controllers but also on filters and view components.
Lets see how to inject class/services.
public class HomeController : Controller

{

    [Activate]

    public TestClass TestClass { get; set; }
}

Asp.Net 5 also supports Dependency Injection into Razorviews via the @inject keyword.

Lets see how to inject TestClass into the view directly and defined a TestClass property by which it can be accessed.
@using WebApplication23

@inject TestClass Testclass
 

@ViewBag.Message

9. xUnit.net
  • In Asp.Net we can say Goodbye Visual Studio Unit Testing Framework and welcome to xUnit.net.
  • Previous versions of Asp.Net MVC, the default testing framework was the Visual Studio Unit Testing Framework. This framework uses the [TestClass] and [TestMethod] attributes to describe a unit test.
[TestClass]
public class ProductTests {
 
    [TestMethod]
    public void TestAddProduct() {
       //Write your code 
    }
 
}
  • In Asp.Net 5 replace the [TestClass] and [TestMethod] to [Fact] attribute. 
  • It means xUnit.net framework uses the [Fact] attribute.
  • xUnit just use [Fact] attribute while previous version unit test framework used [TestMethod] and [TestClass].
public class ProductTests {
 
    [Fact]
    public void TestAddProduct() {
       //Write your code 
    }
 
}

Nov 2, 2015

What is the difference between Asp.Net 5 and Asp.Net MVC 6?

Asp.Net 5
It is an open source cross-platform framework for building modern web applications that can be developed and run cross-platforms like Windows, Linux and the Mac. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. It includes the MVC 6 framework, which now combines the features of MVC and Web API into single web programming framework.

Asp.Net MVC 6
It is a web application framework developed by Microsoft, Which implements the MVC (model-view-controller) patter.














Hope you getting basic idea about next version of Asp.Net. So please keep reading blog post and give your suggestion and comment for improvements.

Next post for Asp.Net 5 improvements.