Tag Archives: .net classes in pune

First MVC 6 and EF 7 Application (using Tag Helpers)

Part 2

In Part 1 of this series we created and configured a basic project using ASP.NET MVC 6. Though the project runs as per expectations and gives a message in the browser, it isn’t yet database driven. In this blog we will add database support to the project in the following ways:

  • By displaying a list of customers from the Northwind database
  • Permit modifications of existing customers
  • Give basic validation capabilities

As a result, the page will display a list of customers from the Customers table of the Northwind database. Each table row has an Edit link. By clicking on the Edit link that will take you to the Edit view such that the customer details can be modified.

Once you edit the details and click the Save button the changes are saved in the database. In case there are any errors they are displayed on the page.

Let’s stasrt with development!

Let’s recall the same project that we created in Part 1 and add Customer class to the Models folder by using the Add New Items dialog. The complete code of this class is shown below:

[Table(“Customers”)]

public class Customer

{

[Required]

[StringLength(5)]

public string CustomerID { get; set; }

[Required]

public string CompanyName { get; set; }

[Required]

public string ContactName { get; set; }

[Required]

public string Country { get; set; }

}

The Customer class is added to the Customers table using the [Table] feature and contains 4 public properties namely CustomerID, CompanyName, ContactName and Country. Basic validations like [Required] and [StringLength] are also added to these properties.

Then add NorthwindDbContext class to the Classes folder and write the following code to it.

public class NorthwindDbContext:DbContext

{

public DbSet<Customer> Customers { get; set; }

protected override void OnConfiguring

(DbContextOptionsBuilder optionsBuilder)

{

optionsBuilder.UseSqlServer(AppSettings.ConnectionString);

}

}

The NorthwindDbContext class represents the data context and hence inherits from the DbContext base class. It consists of a single DbSet – Customers. Notice how the OnConfiguring() method has been overridden to specify the database connection string.

The overridden OnConfiguring() method supplies optionsBuilder parameter. The UseSqlServer() method accepts a d-base connection string. Remember that we stored the database connection string in the ConnectionString static property of the AppSettings class during startup of the application.

Next modify the Index() action of the HomeController as shown below:

public IActionResult Index()

{

using (NorthwindDbContext db = new NorthwindDbContext())

{

List<Customer> data = db.Customers.ToList();

return View(data);

}

}

The Index() action instantiates the NorthwindDbContext and brings all the customers in the form of a List. This List is given to the Index view as its model.

Now, open the Index view and modify it as shown below:

@model List<MVC6Demo.Models.Customer>

<html>

<head>

<title>My First MVC 6 Application</title>

</head>

<body>

<h1>List of Customers</h1>

<table border=”1″ cellpadding=”10″>

@foreach (var item in Model)

{

<tr>

<td>@item.CustomerID</td>

<td>@item.CompanyName</td>

<td><a asp-action=”Edit”

asp-controller=”Home”

asp-route-id=”@item.CustomerID”>

Edit</a></td>

</tr>

}

</table>

</body>

</html>

The Index view displays a list of customers in a table. This code is quite same to MVC 5.x except the Edit link. In MVC 5.x you use ActionLink() HTML helper to render hyperlinks. The above code uses an anchor Tag Helper to achieve the same. The asp-action and asp-controller features points to the action method and the controller. The asp-route-id attribute specifies the ID route parameter to a CustomerID. This way the Edit links will take this form:

/home/edit/ALFKI

To get the Tag Helper intellisense you must add _ViewImports.cshtml file to the Views folder (you can do that using Add New Items dialog). Once added place the following code in it:

@addTagHelper “*, Microsoft.AspNet.Mvc.TagHelpers”

The @addTagHelper directive tells the framework to use Tag Helpers from the specified assembly. You will now get various tag helper related attributes in the Visual Studio intellisense.

Ok. Next, add Edit() action to the HomeController as shown below:

public IActionResult Edit(string id)

{

using (NorthwindDbContext db = new NorthwindDbContext())

{

Customer data = db.Customers.Where(i =>

i.CustomerID == id).SingleOrDefault();

var query = (from c in db.Customers

orderby c.Country ascending

select new SelectListItem()

{ Text = c.Country, Value = c.Country })

.Distinct();

List<SelectListItem> countries = query.ToList();

ViewBag.Countries = countries;

return View(data);

}

}

The Edit action gets a CustomerID as its parameter. Inside, the code brings a Customer matching the supplied ID and sends it to the Edit view. The Edit view needs a list of countries for the Country column. So, a List of SelectListItem (Microsoft.AspNet.Mvc.Rendering namespace) is developed and filled with unique countries from the Customers table. This List is sent to the view through the Countries ViewBag property.

Then add Edit view under Views/Home folder and key-in the following markup in it:

@model MVC6Demo.Models.Customer

<html>

<head>

<title>My First MVC 6 Application</title>

<style>

.field-validation-error

{

color:red;

}

.validation-summary-errors

{

color:red;

}

</style>

</head>

<body>

<h1>Edit Customer</h1>

<form asp-controller=”Home” asp-action=”Save” method=”post”>

<table border=”1″ cellpadding=”10″>

<tr>

<td>

<label asp-for=”CustomerID”>Customer ID :</label>

</td>

<td>

<input asp-for=”CustomerID” readonly=”readonly” />

<span asp-validation-for=”CustomerID”></span>

</td>

</tr>

<tr>

<td>

<label asp-for=”CompanyName”>Company Name :</label>

</td>

<td>

<input asp-for=”CompanyName” />

<span asp-validation-for=”CompanyName”></span>

</td>

</tr>

<tr>

<td>

<label asp-for=”ContactName”>Contact Name :</label>

</td>

<td>

<input asp-for=”ContactName” />

<span asp-validation-for=”ContactName”></span>

</td>

</tr>

<tr>

<td>

<label asp-for=”Country”>Country :</label>

</td>

<td>

<select asp-for=”Country”

asp-items=”@ViewBag.Countries”></select>

<span asp-validation-for=”Country”></span>

</td>

</tr>

<tr>

<td colspan=”2″>

<input type=”submit” value=”Save” />

</td>

</tr>

</table>

</form>

<div asp-validation-summary=”ValidationSummary.All”></div>

<br />

<a asp-action=”Index” asp-controller=”Home”>Go Back</a>

</body>

</html>

The above markup uses the following Tag Helpers:

  • form
  • label
  • input
  • select
  • field validation and validation summary

The asp-action and asp-controller features of the form tag helper are set to Save and Home respectively. This way the form will be POSTed to the Save() action of the HomeController. The asp-for attribute of the label and the input tag helpers specify a model property that is bound with the label and the input field respectively. The asp-items feature of the select tag helper specify that the <option> elements be generated from the Countries ViewBag property.

The field level validations are displayed by adding <span> elements and setting their asp-validation-for attribute to the appropriate model property. This way the model validation errors will be displayed in the <span> elements. The validation summary is displayed in a <div> element by setting its asp-validation-summary attribute to ValidationSummary.All. The look and feel of the validation tag helpers is controlled through CSS classes – .field-validation-error and .validation-summary-errors (see top of the markup).

Now add Save() action to the HomeController and write the following code to it:

public IActionResult Save(Customer obj)

{

using (NorthwindDbContext db =

new NorthwindDbContext())

{

var query = (from c in db.Customers

orderby c.Country ascending

select new SelectListItem()

{ Text = c.Country, Value = c.Country }).Distinct();

List<SelectListItem> countries = query.ToList();

ViewBag.Countries = countries;

if (ModelState.IsValid)

{

db.Entry(obj).State = EntityState.Modified;

db.SaveChanges();

}

return View(“Edit”, obj);

}

}

The code that fills the Countries ViewBag property is similar to before. Then the code finds whether the ModelState is valid using the IsValid property. If the model state is valid the modified Customer details are saved to the database. This is done by setting the State property to Modified and then calling SaveChanges() method.

That’s done! Run the application and check if the customer details could be edited successfully.

We conclude for now. Keep coding!!

Let us know your opinion in the comments sections below. And feel free to refer Microsoft’s site to gather more information.

If you want to improve your skill in ASP.Net and excel yourself in ASP.NET training program; our institute, CRB Tech Solutions would be of great help and for you. Come and join us with our well structured program for ASP .Net.

Stay connected to CRB Tech for more technical optimization and other updates and information.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

First MVC 6 and EF 7 Application (with Empty Project Template)

Part 1

If you are one of that techie who is tracking the progress of ASP.NET 5, you probably know that RC 1 of ASP.NET 5 is available now. This article explains how a simple MVC 6 application could be developed from ground up by using an Empty Project Template. This article is based on the following software:

  • Visual Studio 2015

  • ASP.NET 5 RC 1

  • Entity Framework 7 RC 1

Before you start you need to ensure that you have installed them correctly before you proceed further.

Let’s start here!

Open VS 2015 and select File—–New—-Project menu option. In the New Project dialog choose ASP.NET Web Application, give some project name and click OK button.

In the project template dialog, select Empty under ASP.NET 5 Preview Templates section.

Next, open Project.json file in the VS editor. The Project.json file is a JSON file and contains the entire project configuration like project dependencies, target frameworks and much more. For this example, you have to add some NuGet packages required to develop and run the application. You can enhance project dependencies in two ways:

  • Right click on the References node and choose Manage NuGet Packages. This is very similar to MVC 5.x projects. Once added the NuGet package entries are automatically added to the Project.json file.

  • Add NuGet package dependencies in the Project.json file.

Let’s make use of the later approach.

We won’t go into every minute details of each and every package in this article. It is sufficient to mention that:

  • Microsoft.AspNet.Mvc is the core MVC 6 package

  • Microsoft.AspNet.Mvc.TagHelpers contains tag helpers (discussed later)

  • EntityFramework.MicrosoftSqlServer provides Entity Framework 7 support

Then, right click on the project and choose Add > New Item to open the Add New Item dialog.

Select ASP.NET Configuration File from the list, name it AppSettings.json and click on Add to add the file to project root folder.

The AppSettings.json file has the entire application specific configuration. There is a difference between Project.json and AppSettings.json. The former stores project configuration that is necessary to compile and run the project. The later stores application configuration utilized in the code.

Next you have to add four folders under the project root namely Models, Views, Controllers and Classes. The purpose of the first three is quite obvious. The Classes folder will store other classes required in the application such as a DbContext class. You can give any other name to this folder.

Then add a class called AppSettings in the Classes folder and write the following code:

public class AppSettings

{

public static string ConnectionString { get; set; }

}

The AppSettings class has a single static property – ConnectionString – that intends to hold the database

connection string. This property is taken from the Startup class as discussed recently. Once assigned you can reach out the database connection string from anywhere in the application.

Now open Startup.cs file. The code from the Startup class is implored whenever the application runs. You will find that the Startup class has two methods – ConfigureServices() and Configure(). Both of them have special meaning to the framework and hence their name must remain unchanged.

Edit the Startup file to include a few namespaces and a public constructor.

using Microsoft.AspNet.Hosting;

using Microsoft.Dnx.Runtime;

using Microsoft.Extensions.Configuration;

using Microsoft.Extensions.PlatformAbstractions;

using Microsoft.Data.Entity;

using MVC6Demo.Classes;

namespace WebApplication1

{

public class Startup

{

public Startup(IHostingEnvironment env,

IApplicationEnvironment app)

{

}

public void ConfigureServices(IServiceCollection services)

{

}

public void Configure(IApplicationBuilder app)

{

}

}

}

Take note of the namespaces at the top. They are needed by the code that you will fill in these methods sooner. Also take note that the constructor accepts two parameters: IHostingEnvironment and IApplicationEnvironment. These 3 methods are executed by the framework in the same order – Startup(), ConfigureServices() and Configure().

Next, add the following code to the Startup() constructor.

public Startup(IHostingEnvironment env,

IApplicationEnvironment app)

{

ConfigurationBuilder builder = new ConfigurationBuilder();

builder.SetBasePath(app.ApplicationBasePath);

builder.AddJsonFile(“appsettings.json”);

IConfigurationRoot config = builder.Build();

AppSettings.ConnectionString = config.Get<string>

(“Data:DefaultConnection:ConnectionString”);

}

The Startup constructor mainly reads the AppSettings.json file and stores the database connection string into the AppSettings class. The ConfigurationBuilder class is responsible for reading and loading the configuration information. The SetBasePath() method sets the base path where the configuration file(s) is located. The ApplicationBasePath means the physical path of the project’s root folder.

The AddJsonFile() adds AppSettings.json file to the list of configuration files to be processed. You can have multiple configuration files per project. The Build() method reads the configuration and returns it as an instance of IConfigurationRoot.

To read it, you can use Get<T>() method on the IConfigurationRoot object. Now the database connection string could be accessed from anywhere in the application in typed manner.

Then modify the ConfigureServices() method as shown below:

public void ConfigureServices(IServiceCollection services)

{

services.AddMvc();

services.AddEntityFramework().AddSqlServer();

}

The ConfigureServices() method specifies the features that are available to your application. In this case your application is made available the services of the MVC framework and the Entity Framework.

Now modify the Configure() method as shown below:

public void Configure(IApplicationBuilder app)

{

app.UseStaticFiles();

app.UseMvc(routes =>

{

routes.MapRoute(

name: “default”,

template: “{controller=Home}/{action=Index}/{id?}”);

});

}

The Configure() method tells the framework that you want to use static files feature and MVC features. The static files feature allows you to access static files such as .htm and .html. If you don’t specify this feature and attempt to access the static files you will get an error. Of course, if you don’t need this feature you can skip this line.

The UseMvc() call is important because it not only tells the framework that your application is using MVC but also configures the routing system.

Ok. Now add HomeController to the Controllers folder using the Add New Item dialog. The default HomeController looks like this:

public class HomeController : Controller

{

public IActionResult Index()

{

ViewBag.Message = “Hello from MVC 6!”;

return View();

}

}

Notice that the Index() action returns IActionResult. The Index() action is quite straightforward and simply sets Message property on the ViewBag.

Then add Home subfolder under Views folder. Right click on the Home folder and open the Add New Item dialog again to add Index view to the project.

Add the following HTML markup to the Index view.

<html>

<head>

<title>My First MVC 6 Application</title>

</head>

<body>

<h1>@ViewBag.Message</h1>

</body>

</html>

The Index view simply outputs the Message ViewBag property on the response stream.

Run the application by pressing F5.

We conclude for now. Keep coding!!

If you want to improve your skill in ASP.Net and excel yourself in ASP.NET training program; our institute, CRB Tech Solutions would be of great help and for you. Come and join us with our well structured program for ASP .Net.

Stay connected to CRB Tech for more technical optimization and other updates and information.

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

ASP.NET Web Programming Using The Razor Syntax

In this an Article, we give you an overview of ASP.NET web programming. Even though, it includes almost everything. You’ll need to get started with ASP.NET Web Pages.

Razor Syntax, Server Code and ASP.NET

Razor syntax is a programming syntax for implanting server-based code in a web page. A web page that uses Razor syntax, there are two kinds of contents: server code and client content.

Client content is used in web pages: HTML markup, style information such as CSS, plain text and some client script such as JavaScript.

Razor syntax allows you to add server code to the client content. If there’s server code in the page, the server runs that code first, then it sends the page to the browser. On running on the server, the code can perform tasks that might be more complex to do using client content alone. To server code can dynamically create client content ; it can produce HTML markup or other content on the run and then send it to the browser along with any static HTML.

Razor Syntax

Continue reading

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Prerequisite Before learning ASP. NET

Introduction To LESS & SASS

CRB Tech reviews brings you the basics of LESS & SASS
A very hot topic lately is which CSS preprocessor language should one choose? There are some on-line debates coming up every few days it seems. Now the more concern is which one language is best.

Really short answer: Sass

Slightly longer answer: Sass is better on a whole bunch , but if you are already contented in LESS, that’s cool, you are doing yourself a favor by preprocessing.

Much longer answer: Read on.

Continue reading

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Top 15 ASP.Net Interview Questions and Answers

CRB Tech reviews compiles some important interview questions keeping your interest in concern. Hope this helps you in cracking your interviews.

ASP.NET is the new ASP generation. It is does not fit with Classic ASP
ASP.NET pages have the .aspx extension
When a browser requests an ASP.NET file, the ASP.NET engine reads the file, compiles and executes the words in the file, and returns the result to the browser as plain HTML.
ASP.NET is a development frame for building web pages and web sites with HTML, CSS, JavaScript and server scripting.

ASP.NET supports three different development models:

Web Pages,Model View Controller and Web Forms.

1. What is ASP?

Active Server Pages is a Microsoft’s server-side technology, which helps in developing dynamic and user-friendly Web pages.

2. Define ASP.Net.

It is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.

3. ASP.net advantages?

ASP.Net advantage over ASP :

Compiled Code
Language Support
Strict Coding needs
Event-Driven Programming Model
3rd Party Controls
User Authentication
Easier Configuration & Deployment
Object and Page Caching
Higher Scalability

4. How to maintain session in ASP.NET?

In-process storage.
Session State Service.
Microsoft SQL Server.

In-Process Storage
The default location is the ASP.NET process itself.

Session State Service
It is an alternative to using in-process storage for session state. ASP.NET provides the ASP.NET State Service. The State Service gives you an alternative for storing session state that is not tied quite so closely to ASP. Net’s own process.

Microsoft SQL Server
It is the final choice for storing state information.

5. What is the difference between Server.Transfer and Response.Redirect?

Server.Transfer() : The client sees it as on the requesting page , but all the content is of the requested page.

Response.Dedirect() : Here the client know the physical location (page name and query string as well).

6. Types of comments in asp.net

Single line comments

// for single line comments

Multiple line comments

/* for multi line comments */

XML tags comments

/// XML tags depicted in a code comment

7. Use of @RenderPage() method

@RenderPage() method is used to bring content from separate files.

Example:
<html>
<body>
@RenderPage(“header.cshtml”)
<h1>Hello Web Pages</h1>
<p>This is a paragraph</p>
@RenderPage(“footer.cshtml”)
</body>
</html>

8.What is the folder structure of ASP.NET Web Pages

Logical Folder Structure
Below is a basic folder structure for an ASP.NET web page:

Folders
The “Account” folder has log on and security files
The “App_Data” folder has databases and data files
The “Images” folder has images
The “Scripts” folder has browser scripts
The “Shared” folder has common files
Physical folder structure
Below is a basic folder structure for image
C:\user\Documents\MyWebSites\Demo\Images
From the example above:
The virtual name of a web picture might be “Images/pic31.jpg”.
But the physical name is “C:\usere\Documents\MyWebSites\Demo\Images\pic31.jpg”
URLs and Paths
URLs are to access files from the web: http://www.demo.com/html/html5_intro.asp %>

9. Difference between globalization and localization

Globalization is the process of creating a software product that functions in multiple locales.
Localization is the way of adapting a globalized application, which you have already processed in a localized way, to a particular locale.

10. Define ViewState.
It is the method that the ASP.NET page frame utilize to preserve page and control values between
round trips. When the HTML markup for the page is given, the current state of the page and values that
must be kept during post back are arranged into base64-encoded strings.

11. Name the methods used to force all the validation controls to run

Page.Validate() method

12. What is the difference between Response.Write() and Response.Output.Write() methods?

Response.write() doesn’t give output in format. The latter one helps you to give output in format

Response.write – it writes the text stream , whereas Response.output.write – it writes the HTTP Output Stream.

13. Define Cookie

A cookie is used to identify a user. It is a small file that the server implants on the user’s computer. Each time the same PC requests a page with a browser, it will send the cookie also. With ASP, one can both create and retrieve cookie values.

14. How to Create a Cookie?

The “Response.Cookies” is used to create cookies.

N.B. The command Response.Cookies must appear BEFORE the <html> tag.

In the below example, we are creating a cookie named “fname” and give it the value “ABC” :
<%
Response.Cookies(“fname”)=”ABC”
Response.Cookies(“fname”).Expires=#Jan 10,2015#

15. How to recover a Cookie Value?

The command “Request.Cookies” is used to recover a cookie value.

Example:
<%
firstname=Request.Cookies(“fname”)
response.write(“Firstname=” & firstname)
%>

More questions would be coming next.

We are updating our list of question and answers on .NET

If you are considering to undergo ASP.Net training then our CRB Tech .Net Training center would be very helpful in fulfilling your aspirations. We update ourself with the ongoing generation and that is being portrayed in our ASP.Net course.

Stay connected to this page of CRB Tech reviews for more technical up-gradation and other resources.

CRB Tech reviews will continue to enlighten you with such technical articles on .NET.

Related Articles:

Next Generation Asp.net vNext

PHP VS ASP.NET

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Guidelines To Choose Microsoft .NET Certification Course

Whichever technology in the IT domain you opt for, a certification in it has a great value. It places your CV ahead of others and becomes your USP. As far as .NET technology is concerned, having a .NET certification holds a great value.

Now, after understanding the importance of a certificate, let us move our attention towards covering the various aspects related to Microsoft .NET certifications. This would help to opt for an appropriate certification course.

Microsoft Certification

1.Certification Recommended for Beginners:

For those new to the this technology, Microsoft Technology Associate (MTA) is the prescribed beginning platform for the certifications. Despite the fact that not required, MTA accreditation’s give a strong establishment to those preparing for the Microsoft Certified Solutions Associate (MCSA) and MCSD certifications. The individuals who have been working with the technology, ought to begin with the MCSA or MCSD accreditation. These are essentials for any further certifications. The MCSA certification approves that job seekers have the basic of abilities to get straight down to business. Accordingly, you can choose a certification course.

2.Regarding Validation of Microsoft’s Certificate:

Microsoft Certifications are important in the business sector and will stay significant till the duration organizations are utilizing the technologies covered as a part of the accreditation. After some period, accreditation’s will resign and inevitably will move to a “legacy” status. Legacy Microsoft Certifications will show up on your transcript assigned all things considered. Allude to the resigned certifications page for the most current data with respect to status.

3.Benefits of Passing a .NET certification Exam:

When you pass your first Microsoft Certification exam, you turn into a member from the Microsoft Certified Professional (MCP) group with access to the majority of the advantages provided through the Microsoft Certification Program and the MCP group site. You can impart your transcript to others to demonstrate that you passed that exam and demonstrate your advancement towards a particular certification. Sometimes, e.g. when you pass a MTA or Specialist exam, that solitary exam will likewise acquire you the related certification.

After looking at basic things related to .NET certifications, we would like to inform you that there are various courses available in the market based on the kind of certification you want. You can choose one with proper research and study.

CRB Tech is a premier .NET training institute in India that has a legacy in providing placement and certification related assistance. You can visit CRB Tech for further details regarding the course.

Read Articles:

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Next Generation Asp.net vNext

ASP.Net vNext : General Introduction

Significance -

Changes are extremely quick in programming world and particularly in web advancement world. In the previous decade there have been numerous new upgrades in programming’s like grasping coordinated approach , adjusting decoupled design, moving far from exclusive programming towards open source.

A portion of the imperative things that have turned into a standard in the last couple of years and are normal in any system today are:

Agile. ought to have the capacity to effortlessly suit the overhauls and changes relying upon the upgrades and new examples in the product world. So the new structure discharge cycles could be more incessant and with slightest effect to the current applications.

This is conversely with the past era of systems in which new structure discharge cycles were generally rare and more often than not in years.

Cross stage advancement. Applications ought to have the capacity to keep running on a wide range of stages.

Open source. Since it helps makes a vast designer group and permits everybody to contribute .

Asp.Net Vnext

ASP.NET has developed as a web advancement stage over the years. It has made some amazing progress from web structures to MVC to WebAPI. In the meantime web improvement world has greatly changed subsequent to the underlying arrival of ASP.NET.

ASP.NET vNext which is the following form of ASP.NET is updated starting from the earliest stage and gives answers for a considerable lot of the difficulties confronted while creating web uses of today.

ASP.NET vNext primary elements -

In ASP.NET ,parcel of usefulness is exemplified in various system gatherings and any redesigns to the usefulness ,regardless of how little ,means dispatching another adaptation of the whole assembly. This is not in concurrence with the dexterous advancement universe of today in which changes are exceptionally visit.

Likewise on the off chance that we need to utilize a solitary class from one of these gatherings then the best way to utilize the class is to reference the whole assembly , which may comprise of ton’s of different namespaces which we needn’t bother with.

There are congregations like System.web that contains heaps of usefulness. It contains classes and interfaces that empower program server correspondence. It contains classes like HTTPRequest and HTTPResponse ,it contains classes for various purposes like treat control and document exchange. Likewise It contains the whole Web Forms usefulness.

In the event that we extend the System.Web assembly hub in the elements program, we can investigate the diverse namespaces that it contains.

Advances which were presented later like MVC and WebAPI gave an answer for the solid congregations as NuGet bundles. MVC has a reliance on System.Web while WebAPI have no reliance on System.Web .

1. NuGet Packages

ASP.NET vNext expels the reliance on solid structure congregations. Presently we will be for the most part utilizing NuGet bundles rather than assemblies. In actuality, Cloud enhanced system is only a gathering of NuGet packages.We can say that now Nuget is a critical segment in all the vNext applications.

One essential thing is that there is no System.Web assembly at this point. The usefulness in the System.Web has been moved into littler nuget bundles.

At whatever point we redesign any nuget bundle in the project.json record then it is naturally upgraded in the references hub in the arrangement pilgrim.

2. Cross Platform

ASP.NET – Coupled to the windows environment/IIS

As we are probably aware that ASP.NET is intended to keep running on a windows OS and IIS web server. Though we can utilize Mono to run our applications on different stages yet just Xamarin was in charge of keeping up Mono. Also arranging our applications for these stages required a noteworthy effort. We need to consider the mod_mono/xsp/apache arrangement.

In spite of the fact that we can run our applications on different stages yet there was no simple route for us to build up our applications on non-windows stages.

ASP.NET vNext – Designed as cross stage and host skeptic

Presently we can create and send our asp.net vNext applications on various stages like linux. Also we can have them on servers other then IIS. This is a noteworthy change from the past forms of ASP.NET.

Microsoft now incorporates KRE for Mono so that asp.net vNext applications can keep running crosswise over various stages.

3. Open source

ASP.NET – Proprietary

Despite the fact that MVC and Entity systems which were discharged later are open source and accessible on codeplex, past adaptations of ASP.NET and it’s the greater part of the innovations have been exclusive.

ASP.NET vNext-Fully Open Source

MVC and Entity systems are open source and were accessible on Codeplex, in past variant of ASP.NET. Now ASP.NET vNext is completely open source and it’s code is accessible on GitHub.

.NET Foundation is a gathering for the improvement and collaboraiton of open source .NET technologies. ASP.NET vNext is a piece of .NET Foundation.

4. Side-by-side Execution

ASP.NET – Not simple to specifically upgrade the systems

Generally we have heaps of various applications sent on the generation server. We can have distinctive applications on the server which use diverse adaptations of the system. So we can have couple of utilizations utilizing the structure 3.0 and different applications utilizing system 4.0 and these all applications can exist together joyfully on the same machine with no issues.

ASP.NET vNext – Ability to convey the structure alongside the application

In cloud streamlined mode we can incorporate a duplicate of .NET structure with our asp.net vNext applications and it will utilize that system. This implies since every one of the applications on the server can utilize diverse forms of the system/runtime ,the structure for every application can be redesigned independently without having any effect on whatever remains of the applications.

5. Cloud Ready

ASP.NET – Need to roll out improvements to send applications on the cloud

As cloud is a relatively more current innovation, ASP.NET was not at first intended for the cloud environment. We need to roll out a few improvements in our applications to send them on the cloud. Like making design changes. This implies rolling out critical improvements to our application.

ASP.NET vNext – Cloud prepared

In ASP.NET vNext applications as opposed to bringing the qualities from web.config there are worth suppliers which gets us the right setup values. In certainty there is no web.config record now.

Arrangement settings are gotten from config.json file. This record can be in XML, JSON or INI design.

6. Composable Pipeline

ASP.NET – Little Control over the Request pipeline

In past forms of ASP.NET the request goes through a very much characterized demand pipeline until it is taken care of by the HTTPHandler for the request. We can characterize the event handlers for the HTTP modules and characterize the HTTP handlers. But the request is gone through settled arrangement of segments over which we have next to zero control.

ASP.NET vNext – Ability to add parts to the pipeline

Presently we can expressly indicate the part we need to use in the pipeline. Application host expects a class with the name Startup containing a Configure strategy that takes IApplicationBuilder parameter. This interface has augmentation techniques for the structure builder.UseService() which we have to call to add the support of the solicitation pipeline.

7. MVC 6 – Single Framework

ASP.NET WebAPI , MVC and Web Pages have distinctive usage

In spite of the fact that there is much similitude between MVC ,WebAPI, and Web Pages their executions varies because of chronicled reasons. This is because of the certainty Web API came after MVC. MVC was discharged after Web Forms and it changed the way to deal with web improvement in .NET.

ASP.NET vNext MVC 6 – Commom system

MVC,WebAPI,Web Pages, and Signal R are brought together in a typical structure, MVC 6. MVC 5 relies on IIS while MVC 6 can act naturally facilitated and relies on upon the new asp.net vnext pipeline.

In the event that we need to move to MVC from Web Pages as our application develops we can without much of a stretch do as such now, since they are a piece of the basic structure MVC 6.

8. Roslyn Compiler

ASP.NET – Need to reconstruct the application after code changes

In the past forms at whatever point we alter our code we have to revamp the application for our progressions to produce results. Additionally we don’t have entry to the compiler API in our code as it resembled a black box.

ASP.NET vNext – Dynamic Compilation

ASP.NET vNext comprises of up and coming era of compilers called Roslyn.Roslyn is an open source compiler platform. It uncovered an article situated API .We can utilize this API to utilize elements of roslyn, for example, code examination in our code.In the past variants we needed to utilize instruments for code investigation.

For .NET training and placement reviews, please do visit CRB Tech Reviews.

Related Articles:

Why Microsoft’s Dot Net Core Is The Future Of Its Development Platform?

Best 13 Free .NET Development Tools

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

SQL Cursors and It’s Use In VB.NET

In this blog from CRB Tech Reviews, we will see in detail the concept of SQL cursors and it’s use in VB.NET.

Cursor Definition:

Cursor is basically a database object used to recover data from a result set line by line, rather than the T-SQL commands that work on every one of the rows in the result set at one time. We utilize cursor when we have to update records in a database table in singleton style implies line by line.

Now we will see the basic syntax of a cursor:

DECLARE cursor_name CURSOR
[LOCAL | GLOBAL] –scope of cursor is defined over here.
[FORWARD_ONLY | SCROLL] – the direction of cursor movement is defined in this line (forward/backward)
[STATIC | KEYSET | DYNAMIC | FAST_FORWARD] – basic type of cursor is declared over here.
[READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] – define locks
FOR select_statement – SQL Select statement is mentioned
FOR UPDATE [col1,col2,…coln] – names of columns that need to be updated are passed here as parameters.

This is the syntax to define a SQL cursor. Declare Cursor SQL Comaand is utilized to define the cursor with numerous alternatives that affect the scalability and loading conduct of the cursor.

Cursor Life Cycle:

1. Cursor Declaration:

For declaring a cursor, one needs to define a SQL statement which returns a result set.

2. Open:

Execute the SQL statement defined by the cursor if you wish to populate and open the cursor.

3. Fetch:

Once a cursor is opened, then we can access the rows from the cursor one by one or in bulk manner for data manipulation.

4. Close:

A cursor needs to be closed explicitly, once data manipulation is done.

5. Deallocate:

Once the job is done, the cursor needs to be freed for further use. All system resources associated with the cursor are released using this command. It is just like freeing the memory.

Scrollable Cursors:

Developers may declare cursors as scrollable or not scrollable. The scrollability depicts the direction in which a cursor can move.

A line of code may position a scrollable cursor anyplace in the result set utilizing the FETCH SQL command. The SCROLL keyword must be determined while declaration of the cursor. The default value is NO SCROLL, albeit distinctive language ties like JDBC may apply an alternate default.

Using a non-scrollable (or forward-only) cursor, you can FETCH every line at most once, and the cursor naturally moves to the following line. After you get the last line, on the off chance that you fetch once more, you will put the cursor after the last line and get the accompanying code: SQLSTATE 02000 (SQLCODE +100).

DECLARE cursor_name sensitivity SCROLL CURSOR FOR SELECT … FROM …

Scrollable cursors can possibly get to the same row in the result set at various times. In this manner, data changes (insert, delete, update operations) from different transactions could affect the result set. A cursor can be SENSITIVE or INSENSITIVE to such data adjustments. A sensitive cursor grabs data changes affecting the outcome set of the cursor, and an insensitive cursor does not. Moreover, a cursor might be INSENSITIVE, in which case the DBMS tries to implement sensitivity however much as could be expected.

A Cursor affects the execution power of the SQL Server since it utilizes the SQL Server instances’ memory, diminish concurrency, diminish network bandwidth and lock resources. Consequently it is compulsory to comprehend the cursor types and its capacities with the goal that you can utilize appropriate cursor as indicated by your necessities.

You ought to maintain a strategic distance from the utilization of cursor. Essentially you ought to utilize cursor options like WHILE loop, sub queries, Table variables and temporary variables. We ought to utilize cursor all things considered when there is no alternative with the exception of cursor.

Conclusion:

Utilizing SQL Cursors inside a loop will empower you to spare a great deal of time and handling power to get the best execution out of your SQL databases. If it’s not too much trouble keep investigating the universe of SQL to see everything that you can do with databases.

To learn more about databases and .net, you can inquire about VB .NET courses.

For .NET training and placement reviews, please do visit CRB Tech Reviews.

Related Articles:

.Net programming concepts explained in detail

WHY  SHOULD YOU LEARN VISUAL BASIC (VB.NET) ?

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

An Overview and Uses Of Reactive Exteansion(Rx) in .NET

Significance of RX -

Clients expect a constant flow of data and they have their tweets regularly over it. Their request breeding good currently. They need precise prices beginning now. Their web recreations ought to be responsive. You would like to own the result pushed to you once it’s ready. Spectacularly higher, once operating with result sets, you would like to urge singular results as they’re ready. You’d like to not rest for the complete set to be ready before you see the first line. The globe has moved to push; purchasers square measure holding a firm stand for United States of America. developers have apparatuses to push data and this is often easy. developers want devices to retort to push data.

Welcome to Reactive Extensions for .NET (Rx) -

This book can be utilized by any .NET developer interested in the IObservable<T> and IObserver<T> interfaces that have appeared in .NET 4. The Reactive Extensions libraries from Microsoft square measure the executions of those interfaces, that square measure quickly obtaining footing with Server, shopper, and .NET developers alike. Rx is Associate in Nursing effectively helpful advancement of device. Rx empowers engineers to take care of problems in a very wealthy, natural and decisive style; frequently desperately less code was conceivable, while not Rx. By utilizing LINQ, Rx gets the possibility to brag the quality benefits of a LINQ implementation1.

Coordinated –  

LINQ is coordinated into the C# idiom.

Unitive –  

Utilization of LINQ permits you to influence your current aptitudes for questioning information very still (LINQ to SQL, LINQ to XML or LINQ to elements) to inquire the information in movement. You could consider Rx LINQ to events. LINQ permits you to move from different ideal models into a typical world-view. For instance you can move a standard .NET event, a non-concurrent technique call, a Task or maybe an outsider middleware API into a solitary normal Rx world-view. By utilizing the current language of decision and utilizing recognizable administrators like Select, Where, GroupBy and so on, engineers can justify and convey plans or code in a typical structure.

Extensible -

You can amplify Rx with your self cutomized question administrators (expansion techniques).

Decisive -

LINQ permits your code to peruse as an announcement of what your code does and leaves the ‘how -‘ to the usage of the administrators.

Composable -

LINQ components, for example, augmentation strategies, lambda sentence structure and question cognizance punctuation, give a familiar API to the developers to devour. Inquiries can be built with various administrators. Questions can then be made together to further creation of composite inquiries.

Transformative -

Inquiries can change their information starting with one write likewise onto the next. An inquiry may make an interpretation of a solitary quality to another worth, accumulated from a succession of qualities to a solitary normal esteem or grow a solitary information esteem into an arrangement of qualities.

When Rx is appropriate -

Rx offers a characteristic world-view for managing arrangements of events. An arrangement can contain zero or more events. Rx ends up being most important when making groupings out of events.

Whether utilize Rx -

Overseeing events like these is the thing that Rx was worked for :

  • UI events like mouse move, catch click
  • Space events like property changed, gathering upgraded, “Request Filled”, “Enlistment acknowledged” and so on.
  • Base events like from document watcher, framework and WMI occasions
  • Joining events like a telecast from a message transport or a push occasion from WebSockets API or other low inactivity middleware like Nirvana
  • Joining with a CEP motor like StreamInsight or StreamBase.
  • Curiously Microsoft’s CEP item StreamInsight, which is a piece of the SQL Server family, likewise utilizes LINQ to assemble inquiries over gushing events of information.

Rx is likewise extremely appropriate for presenting and overseeing simultaneousness with the end goal of offloading. That is, playing out a given arrangement of work simultaneously to free up the present string. An exceptionally prominent utilization of this is keeping up a responsive UI.

You ought to consider utilizing Rx in the event that you have a current Ienumerable<T> but  that is endeavoring to model information in movement. While IEnumerable<T>can modulize information in movement (by utilizing lethargic assessment like yield return), it most likely won’t scale. Repeating over an IEnumerable<T> will expend/obstruct a string. You ought to either support the non-blocking nature of Rx by means of either IObservable<T> or consider the async highlights in .NET 4.5.

Could utilize Rx –  

Rx can likewise be utilized for non-concurrent calls. These are viably successions of one events.

Consequence of a Task or Task<T>

Consequence of an APM strategy call like FileStream BeginRead/EndRead

You may discover the utilizing TPL, Dataflow or async watchword (.NET 4.5) ends up being a more normal method for creating non-concurrent techniques. While Rx can help with these situations, if there are other more fitting systems available to you ought to think of them as first.

Rx can be utilized, however is less suited for – presenting and overseeing simultaneousness for the motivations behind scaling or performing parallel calculations. Other devoted systems like TPL (Task Parallel Library) or C++ AMP are more suitable for performing parallel register escalated work.

See more on TPL, Dataflow, async and C++ AMP at Microsoft’s Concurrency landing page.

Won’t utilize Rx -

Rx and particularly IObservable<T> is not a substitution for IEnumerable<T>. Attempting to take something that is actually pull based and drive it to be push based.

Making an interpretation of existing IEnumerable<T> qualities to IObservable<T> just so that the code base can be “more Rx”

Message lines. Lines like in MSMQ or a JMS usage, for the most part, have constitutionality and are by definition consecutive. IEnumerable<T> is a characteristic fit for here.

By picking the most ideally equipped apparatus for the employment your code ought to be less demanding to keep up, give a better execution and you will likely improve support.

Rx in real life -

Embracing and learning Rx can be an iterative methodology where you can gradually apply it to your base and area. In a brief span you ought to have the capacity to have what it takes to create code, or decrease existing code, to inquiries made out of straightforward administrators. For instance this basic ViewModel is all as expected to code to coordinate an inquiry that is to be executed as a client sorts.

public class MemberSearchViewModel : INotifyPropertyChanged
{
//Fields removed…
publicMemberSearchViewModel(IMemberSearchModel memberSearchModel,
ISchedulerProvider schedulerProvider)
{
_memberSearchModel = memberSearchModel;
//Run search when SearchText property changes
this.PropertyChanges(vm => vm.SearchText)
.Subscribe(Search);
}
//Assume INotifyPropertyChanged implementations of properties…
public string SearchText { get; set; }
public bool IsSearching { get; set; }
public string Error { get; set; }
public ObservableCollection<string> Results { get; }
//Search on background thread and return result on dispatcher.
private void Search(string searchText)
{
using (_currentSearch) { }
IsSearching = true;
Results.Clear();
Error = null;
_currentSearch = _memberSearchModel.SearchMembers(searchText)
.Timeout(TimeSpan.FromSeconds(2))
.SubscribeOn(_schedulerProvider.TaskPool)
.ObserveOn(_schedulerProvider.Dispatcher)
.Subscribe(
Results.Add,
ex =>
{
IsSearching = false;
Error = ex.Message;
},
() => { IsSearching = false; });
}

}

While this code scrap is genuinely little it supports the accompanying necessities -

  • Keeps up a responsive UI
  • Underpins timeouts
  • Knows when the pursuit is finished
  • Permits results to return each one in turn
  • Handles mistakes
  • Is unit testable, even with the simultaneousness concerns
  • On the off chance when a client changes the pursuit, wipe out ebb and flow look and execute new hunt with new content.

To deliver this specimen is very nearly an instance of making the administrators that match the necessities into a solitary question. The inquiry is little, viable, explanatory and far less code-related than “moving your own”. There is the additional advantage of reusing an all around tried API. The less code you need to compose, the less code you need to test, troubleshoot and keepng up. Making different questions like the accompanying is basic -

  • ascertaining a moving normal of a progression of qualities e.g. administration level understandings for normal latencies or downtime
  • joining events information from numerous sources e.g.: query items from Bing, Google and Yahoo, or sensor information from Accelerometer, Gyro, Magnetometer or temperatures
  • gathering information e.g. tweets by theme or client, or stock costs by delta or liquidity
  • sifting information e.g. web amusement servers inside an area, for a particular diversion or with a base number of members.

Push is here. Outfitting yourself with Rx is a capable approach to live up to clients’ desires of a push world. By comprehension and making the constituent parts out of Rx you will have the capacity to make short work of complexities of preparing approaching events. Rx is set to wind up an everyday piece of your coding knowledge.

For .NET training and placement reviews, please do visit CRB Tech Reviews.

Related Articles:

.Net programming concepts explained in detail

WHY  SHOULD YOU LEARN VISUAL BASIC (VB.NET) ?

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr

Basic Terms in ASP.NET MCV used for Saving Data on the Client

According to Vogel, the first law of client’s server figuring is: – “The client’s PC ought to be viewed as a free, boundless asset that ought to be abused uncivilly.”  The conspicuous support is that, by utilizing the client’s assets, as opposed to your server’s assets, you enhance the adaptability of your application. What’s more, by decreasing treks and payloads between the client and the server, you likewise make a more responsive application for the client.

Ajax is a type of arrangement that shares information handling to the client. JSX+React  which Vogel told about in his TypeScript segment even moves producing the page’s HTML to the client’s PC. The point of this segment, utilizing localStorage, permits you to exchange information stockpiling to the client’s PC.

Be that as it may, this article will demonstrate to pass information from your View to your client in a way that backings sharing that information on the client’s PC.

Words of Cautions  -

The localStorage is a component of the HTML5 determination, so more established programs don’t survive with it.

The programs force an extreme point on the measure of information you’re permitted to store in localStorage – ( breaking point is set to zero in a few programs –  running in “private” mode)

To manage that you’ll have to ensure -
(1).    localStorage is accessible
(2).    you haven’t hit your ultimate point

This segment demonstrates the  generally accepted methods to test for both conditions and to guarantee you won’t surpass your ultimate point.

There is an additional variety of programs upon How –  ‘localStorage’ functions. Testing those distinctions haven’t been sufficiently noteworthy to make swear off utilizing localStorage.

One final note before getting to the code -

You have to perceive that localStorage isn’t fixing to a page – rather, it’s fixing to the page’s space (the front part of the page’s URL). This enhances both in taking decisions while utilizing localStorage: Use it just for the information that is regular to all applications in the same area (client inclinations jumps to psyche) or figure out how to keep every application’s nearby information separate from different applications from the same space.

One technique for keeping every application’s information separate from different applications in the same space -

Initially, How would you know you can utilize localStorage? The accompanying code both – verifies whether the program underpins localStorage and that there’s enough space accessible (there’s no immediate approach to check for the amount of space you have accessible). The code first verifies whether localStorage is assisted by endeavoring to recover a reference to localStorage. On the off chance that makes the code work then verifies whether there’s space accessible by endeavoring to store a thing in localStorage. In the event that the majority of that works then the code expels the testing factor from localStorage. On the off chance that one of those falls flat (either on the grounds that the program doesn’t assist localStorage or there’s no accessible space) the code will explode, tossing you into the special case where you can do whatever appears to be proper:

<script>

attempt { var storTest = window[‘localStorage’];

storTest.setItem(“”, “.”);

storTest.removeItem(“”); }

catch(e) { alert(“Please leave”); }

You can, obviously, utilize modernizer to verify whether the client’s program assist’s localStorage yet modernizer won’t let you know whether there isn’t any space accessible. Whereas, this code does both.

Taking in concern : Testing

localStorage has a reasonable capacity that evacuates the greater part of the sections in localStorage on the client’s PC.  Taking into consideration, with the unmistakable capacity’ you’re wiping out your application’s nearby information as well as all information kept away for any application from the same area.

In any case, keeping in mind the end goal to test your application being developed, you’ll likely locate the reasonable capacity accommodating in wiping out localStorage with the goal that you can test how your page acts when there’s no information present. The keen thing to do is put your call to clear on a utility page that you can call when you need to get out localStorage.

For .NET training and placement reviews, please do visit CRB Tech Reviews.

More Related Articles :

New Updates : C# and VB Features in Visual Studio 2015 Update 2

FOR MVC DEVELOPERS THE FEATURES OF ASP.NET CORE

ASP.NET TO MVC 3 MIGRATION

Don't be shellfish...Buffer this pageEmail this to someoneDigg thisShare on FacebookShare on Google+Share on LinkedInPrint this pageShare on RedditPin on PinterestShare on StumbleUponTweet about this on TwitterShare on Tumblr