Sunday, July 31, 2011

Help Microsoft to improve Visual Studio performance

Visual studio is a great IDE(Integrated Development Environment) and we love it all. There are many people who are still complaining about visual studio performance. Now Microsoft Visual Studio team has release PerfWaston diagnostic tool that helps Visual Studio team to diagnose the performance problem. Also this tool will automatically report performance and other problem.

So please download the PerfWaston tool from below link.
http://visualstudiogallery.msdn.microsoft.com/fa85b17d-3df2-49b1-bee6-71527ffef441?SRC=Home

You can find more details about PerfWaston in following link.
http://blogs.msdn.com/b/visualstudio/archive/2011/05/02/perfwatson.aspx

Share:

SQL Management Studio in Visual Studio 2010

Microsoft Visual Studio 2010 is a great IDE and everyday I am discovering something new about it. Today I am also going to explain new feature of Visual Studio 2010. In this post I am going to Transact SQL Editor feature in Visual Studio 2010.

Visual Studio 2010 Ultimate Edition provides this great feature. You can run you SQL Queries in visual studio 2010 itself with all intellisense and all the stuff that SQL Server provides. Let’s explore in details.
To connect the database of your SQL Server in Visual studio Go to Data->Transact SQL Editor –>New Query connection like following.

SSMS 

Now once you click it will open the dialog box for connection SQL server like it. If you don’t have install anything it will install SQL Server 2008 express edition with Visual Studio 2010 Ultimate Edition. The dialog appear like following.


SQLServer

Once you are done with the connection it will open full fledge Query editor windows with intellisesnse like following.

Intellisense

Also it can connect to any databases including your SQL Azure databases also. Isn’t that great. You don’t need SQL management studio at all for the basic database operations. That’s it. Hope you like it. Stay tuned for more.. Till then happy programming.


Shout itkick it on DotNetKicks.com
Share:
Monday, July 25, 2011

Hello World application with ASP.NET pages and WebMatrix

In this post I am going to explain how we can create fast web sites without worrying about code and other stuff. Microsoft has introduced a new web development tools called ‘WebMatrix’. It’s a free tool provided by Microsoft to create website fast.

What is WebMatrix?

Web Matrix is a free tool provided by Microsoft for website development. You can develop websites lightening fast with the help of Microsoft Web Matrix. It includes IIS express(express version of IIS) and SQL Server Compact (Compact edition of SQL Server database). It also contains lots of popular web application templates like wordpress ,blogengine etc. You can also create dynamic web pages with WebMatrix. Here is the link from where you can download WebMatrix.

http://go.microsoft.com/fwlink/?LinkID=205867

What is asp.net Pages?

 

ASP.NET pages are one of easiest way to create websites pages. You can use Razor and all other syntax to create webpages. You can write script tag to write dynamic code and you can also write HTML in same page.

Creating Hello World application with WebMatrix

 

Now let’s create a very basic Hello World application without writing any dynamic code. So let’s first open WebMatrix and it will show start up page like following.


WebMatrix

Here you will have four options My Sites, Site from Open Source Gallery, Sites from Template and Site from folder. I want to create a new site so I have clicked on Site from template. Once you click on that you will be presented to Site from template dialog where you have different options like Empty Site,Starter site,Bakery etc. like following.

EmptySite

As I want to create a very basic site so I have clicked Empty site.Once you click on empty site your site will be created and you will presented to following screen.

SiteStructure

Now its time to create new page for the site. So I have clicked File->New Pages and you will be presented to page dialog like following where different options are available like HTML,CSS,Jscript,CHTML etc.

CSHTML

I have selected CSHTML as I want to have my site dynamic so I have one page called default.cshtml and then I have written Hello world HTML like following.

<!DOCTYPE html>

<html lang="en">

   <head>

       <meta charset="utf-8" />

       <title></title>

   </head>

   <body>

       <h1>Hello World</h1>

   </body>

</html>

Now let's run site in browser and following is the output.

HelloWorld

That’s it. It’s so easy. In future post I am going to write some dynamic code using Microsoft Web Matrix.Hope you like it..Stay tuned for more.. Till than happy programming..

kick it on DotNetKicks.comShout it
Share:
Sunday, July 24, 2011

Visual Studio 2010 styles

I have been working with visual studio 2010 yesterday and I was searching some thing and same time I have found one great site for Visual Studio styles. http://studiostyl.es/ This site is cool and you can find lots of visual studio 2010 styles of your choice. Here is the screenshot of site.


Style

You can create your own color schemes for visual studio also. I have downloaded the first one(Son of Obsidian). It will be visual studio settings file.Once you downloaded you can import like following. GoTo Tools->Import and export settings in Visual Studio 2010. Once you click this It will import and export dialog like following.


ImportExportDialog

I have selected Import selected environment setting and clicked next on next screen you will have option to save your visual studio settings like following.

SaveYourSettings

Clicking on next you will have options for different visual studio 2010 Style like following.

ChooseStyle

Click on browse and select your downloaded style like following.

OpenStyle

Click on open and then you will represented to recent file options click next You will come to final settings wizard like following.

FinishStyle

Click on finish now our style is applied.Close the dialog and open your project and you can see new color scheme for your visual studio 2010 like following.

VisualStudio2010Style

That’s it. Hope you like it. Stay tuned for more..Till then happy programming..


kick it on DotNetKicks.comShout it
Share:
Friday, July 22, 2011

Box Selection in Visual Studio 2010

Every day I am discovering something new with Visual Studio 2010 and In this post I am again going to explain you new interesting feature of Visual Studio 2010. We all required to modify the code in bulk some time and there is a new features for Visual Studio 2010 which enables to made changes in multiple line at same time. Let’s take a simple example like following.


using System;

namespace Parallel
{
  class Program
  {
         private int a=10;
         private int b=10;
         private int c=10;

         static void Main(string[] args)
         {

         }  
  }
}

In above code I have three private variable a,b and c and now I want to make them protected. There is two way either I do manually one by one or I can do it with box selection and modify them together. It very easy to use this feature Press ALT+ SHIFT and draw box with help of mouse on the code which you need to modify like following.



SelectedBox

Now I want to make it protected so I started writing protected and it will modify all the line at same time like following.

ChangedCode

And now my code is like following.

using System;

namespace Parallel
{
  class Program
  {
         protected int a=10;
         protected int b=10;
         protected int c=10;

         static void Main(string[] args)
         {

         }  
  }
}

That's it. Hope you like it… Stay tuned for more…Till then Happy programming.




Shout itkick it on DotNetKicks.com
Share:
Tuesday, July 19, 2011

Windows Azure Table Storage in detail

Windows Azure table storage provides two kind of storage 1) SQL Azure and other one is 2) Table,queue,blob and other storage like drives etc. In this blog post I am going to explain Table storage in details.

What is Windows Azure Table Storage:


Windows Azure table storage is a service provided by Azure platform to store data in form relational tables in windows azure storage instead of normal RDBMS System. It is a structured storage provided by Azure platform. The table storage which you create with windows azure is Unique. An account of windows azure can have any number of table storage.

Table Storage in details:


There are three important aspects when you deal with windows azure table services. Table,Entities and Properties. Here table is similar to storing data in spread sheet or storing in table with relational databases. Entity represents particular row in the table and property represents a particular column or cell in row. There are three system properties of each entity.
  1. Partition Key
  2. Row Key
  3. Time Stamp

Partition Key:


The partition key is a unique key value that is used to group, or partition, related data on same storage node. As we all know that internally data will stored in hard disks in table storage so whenever your data grows then at that time your data may be partitioned into multiple hard drives. At that time this partition key will keep all the data on the same storage nodes. So partition key is used to organize data in storage.

Row Key:


Row key uniquely identifies a specific entities on a partition. Different partition keys may share the same row key, but the same partition may not have two entities with the same row key.The Row Key property is optional and may also be an empty string if all that is needed for uniqueness is the Partition Key value
The PartitionKey and RowKey properties both have String values (up to 1KB in size) and together they form a unique primary key for an entity in a table.

TimeStamp:


Time stamp property has a DateTime value maintained by the Windows Azure Table System to facilitate optimistic concurrency.

Column Types in Table Storage:


Table storage in windows azure support following types of columns.
  1. byte[]
  2. bool
  3. DateTime
  4. double
  5. Guid
  6. Int32 or Int
  7. Int64 or long
  8. String.
In next post I will create application for table storage. That’s it. Hope you like it. Stay tuned for more.. Till then happy programming..

Shout it

kick it on DotNetKicks.com
Share:
Sunday, July 17, 2011

New Improved IntelliSense with Visual Studio 2010

I have posted lot many things about Visual Studio 2010 features because its a great IDE(Integrated Development Environment).Today I am going to write about IntelliSense improvement in Visual Studio 2010. Today when I was working with Visual Studio 2008 for a old project(Nowadays I am working with Visual Studio 2010), I have found new improve IntelliSense feature in Visual Studio 2010.


Filtering:


Visual Studio 2010 IntelliSense is filtered better than Visual Studio 2008. I have created a sample application and I am writing Console.ReadLine that you can see in following image its filtering with read only.

Intellisense

In earlier version it was not possible.Hope you like it. Stay tuned for more.. Happy Programming..

Shout it

kick it on DotNetKicks.com
Share:
Saturday, July 16, 2011

Introduction to Windows Azure

Recently I have got chance to work with SQL Azure and I loved it. So that’s why Here I am going to start series of post on Windows Azure and SQL Server Azure. In first post of this series I am going to introduce you windows azure platform. I know there are many peoples that may find this post as very beginner level but We all have started from beginner level at some point of time. So It’s better to start at beginner level and then go through step by step overview.

What is Windows Azure:


Well simplest answer in this simple language to above question is “ It’s a operating system which hosts number of services on cloud”. Microsoft has developed this platform to leverage services into the cloud. In azure world you can have application and databases running on cloud. You don’t have to worry about the infrastructure of servers and all other stuff. They will be automatically done by windows azure plate form itself. All you have need to do buy a windows azure services and then developed application with the SDK provided by Microsoft and deploy it. Your application will be ready to serve. You can add multiple instances of server as per your application requirement.

Developing windows azure application is slightly different from normal traditional applications. But developer can still use visual studio 2010 for that. It can also host PHP,Java and other applications also. It does not required to have proprietary software to write application. In fact you can use windows azure with Visual Studio 2010 express edition also.

Roles:

In windows azure everything is based on Roles. There are two kind of roles available for windows azure.
  1. Web Role
  2. Worker Role
Web Role:
You can think web role as web server where we can host our web application or web site. They provide public computers to connect your application like a simple website url i.e. myapplication.cloudapp.net etc. You can run the application with standard HTTP and HTTPS ports also. Even you can have multiple web roles for your single application as per your requirement.
Worker Role:
You can defined Worker Role as some kind of services that works behind the web application. i.e. A window service to create thumbnail of images to display it in web application or a caching service etc. Worker roles are also available outside the world they can talk to any application.

Storage Resources available in Windows Azure:


Azure provide two kind of storage facility In built storage in Azure where we can store data in blobs,queues,tables, drives which are used for following purposes.
  1. Blob- Used to store large amount of data.
  2. Queues-Background work processing
  3. Table- Storage for fast retrieval
  4. Drives-NTFS Formatted page blobs
Windows Azure also provides storage facility with SQL Azure.SQL Azure is a database in cloud where you can almost have all functionalities of SQL Server in cloud. I will cover about above topic in details in forthcoming posts.

All types of roles comes in four verities: Small,Medium, Large and Extra large. All roles are virtual machines. Each represents an increase in pricing and has a different set of specifications that govern how much RAM, local storage space and CPU cores are available to the role as described below:


Size CPU Cores Memory Disk Space for Local Storage Resources
Small 1 1.7 GB 250 GB
Medium 2 3.5 GB 500 GB
Large 4 7 GB 1000 GB
Extra-large 8 14 GB 2000 GB


That’s it. Hope you liked this post. In forthcoming post I am going to explain you can use windows azure in your application with example. Till that stay tuned for more.. Happy programming..


Shout it

kick it on DotNetKicks.com
Share:
Friday, July 15, 2011

Some important attributes in EFCodeFirst

In today’s post I am going to explain some of the important attributes in EFCodeFirst. Whey you do scaffolding with ASP.NET MVC this all attributes are where much important. So Let’s explore all the attributes.

Key Attribute:

When you put this attribute in the class it tell that this property is part of the primary key and If you use code first when its create table based on this entity then it will be a part of primary key of table. Here is the sample example of that.
[Key]

public int ArticleId { get; set; }
Here article ID will act as primary key.

Foreign Key Attribute:

This attribute is very useful when you deal with interrelated tables You can specify the column in entity which is foreign key for that Like following.
[ForeignKey("CategoryId")]

public ICollection<Category> Categories { get; set; }
In above example CategoryId is a foreign key of category table to article table.

ScaffoldColumn Attribute:

When you Scaffold your application with ASP.NET MVC scaffold feature or dynamic data with asp.net webforms this attribute will tell that this column need to have field for that. You can write that column like following.
[ScaffoldColumn(false)]

public int ArticleId { get; set; }
Here it will tell article id will not have UI in scaffoling.

StringLength Attribute:

This attribute is used to specify the maximum length of a string. This attribute is very usefull in validation and other stuff. This attribute only applied to the Stringlength property like following.
[StringLength(512)]

public string Title { get; set; }
Here in the above code it tell that title could not have more then 512 character string.

There lots of other attributes also. I will blog about it in future posts. Hope you liked this. Stay tuned for more..Happy Programming.

Shout it

kick it on DotNetKicks.com
Share:
Tuesday, July 12, 2011

Parallel for loop in C# 4.0

Now days we are getting our computer equipped with more and more power even now we are getting quad core processor is also at lower price. Since we have multicore processors are now so we can take advantages of multicore processor with parallel execution in C# 4.0. There are some time consuming task for the computer for example a long for loop or similar kind of things. This kind of task can be done parallel with parallel class in C# 4.0.

Now in C# 4.0 you have the Parallel static class with the help of this you can perform task parallel very easily. In this post I am going to explain Parallel for loop. Let’s take a very simple example. First lets create a example with simple for loop. Following is code for that.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Parallel
{
class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i <=100000; i++)
        {
            Console.WriteLine(i);
        }
       
    }
}
}

In the above its a normal loop which increments I and then print the that number into the console screen and Here is the output.

Ouput1

Here in the output you can see its sequentially process one by one now lets change this code to parallel for loop like following.

using System;

namespace Parallel
{
class Program
{
    static void Main(string[] args)
    {
        System.Threading.Tasks.Parallel.For(0, 100000, i =>
        {
            Console.WriteLine(i);
        }
        );
        Console.ReadLine();
    }
}
}

Here in the above code you can see that I have used parallel for which also prints the Incremented integer in console application. Now let’s run that code and see the output as following.

Output2

If you see the output very carefully then you can see that its not processing sequentially one by one but its processing it parallel and its will be much faster if you have multicore processor in your computer. But beware if you are going to run in simple processor computer its going to take more time then normal computer. That’s it. Hope you liked it.. Stay tuned for more.. Till that happy programming..



Share:
Wednesday, July 6, 2011

CRUD Operation with ASP.NET MVC and EFCodeFirst Part-2

In the previous post I have already explained How we can list data from database easily with the help of EFCodeFirst . In this post I am going to explain How we can complete Create,Edit,Delete and Details operations within 10 minutes. So let’s first Start with Create a new Customer.I am going use same example of customer from previous post. So we have customer controller there so Let’s first create a new view for Create via Selecting View in Create() method of Customer Controller and Clicking on Add View and dialog box will open for add view like following.

CreateView

As you can see in the above template I have selected Customer Model Class for strongly typed view and Selected Scaffold template as Create once you click Add your view will be ready. Now its time to write for code in customer controller to Add Customer. So I have modified Create Method of customer controller which we have created like following.

[HttpPost]
public ActionResult Create(Models.Customer customer)
{
  try
  {
      using (var databaseContext = new Models.MyDataContext())
      {
          databaseContext.Customer.Add(customer);
          databaseContext.SaveChanges();
      }
    
      return RedirectToAction("Index");
  }
  catch
  {
      return View();
  }
}

That's it. We have done with Create Customer now. In the above databasecontext add method will add customer and SaveChanges method will save changed to database.
Now once we are done with Add its time to create edit and update functionality. Let’s first Add a view via Selecting view with Edit Method in clicking on Add view. Once you click a dialogbox for add View will open for that like following.

EditView

As you can see you I have selected scaffold template as Edit and I have Created Strongly typed view with Customer class. Once you click add it will create a new view for Edit. Now our Edit View is ready so let’s write code for Edit/Update in database. So first we have to modify Edit(int Id) method like following which will return specific customer with View. Following is a code for that.

public ActionResult Edit(int id)
{
  using (var databaseContext = new Models.MyDataContext())
  {
      return View(databaseContext.Customer.Find(id));
  }
}

Now let write code to update the changes to database. So for that I have modified another ActionResult Edit of customer controller like following.

[HttpPost]
public ActionResult Edit(int id, Models.Customer customer)
{
  try
  {
      using (var databaseContext = new Models.MyDataContext())
      {
          databaseContext.Entry(customer).State= System.Data.EntityState.Modified;
          databaseContext.SaveChanges();
      }
      return RedirectToAction("Index");
  }
  catch
  {
      return View();
  }
}

That's it we are done with the edit stuff.In above code the state modified will tell databasecontext that customer details is modified and savechanges will save changed to database. Now its time to create view for delete functionality. So I have clicked on Add View and Created a view for delete like following.

DeleteView

Here I have create Strongly typed view with Delete Scaffold Template. Now let’s modified both Delete Action Result in Customer Controller class. First Action result will return customer which we are going to delete and another delete action result with id will delete the customer from database and then it will return to main customer page. I have modified the code for both as following.

// GET: /Customer/Delete/5

public ActionResult Delete(int id)
{
  using (var databaseContext = new Models.MyDataContext())
  {
      return View(databaseContext.Customer.Find(id));
  }

}

//
// POST: /Customer/Delete/5

[HttpPost]
public ActionResult Delete(int id,Models.Customer customer)
{
  try
  {
      using (var databaseContext = new Models.MyDataContext())
      {
          databaseContext.Entry(databaseContext.Customer.Find(id)).State = System.Data.EntityState.Deleted;
          databaseContext.SaveChanges();
      }

      return RedirectToAction("Index");
  }
  catch
  {
      return View();
  }
}

Here I have done something different then editing stuff to demonstrate the feature of Entity framework. You can also use Id for finding the current customer and then change its state to delete and SaveChanges will save that to in database. So now we are done with delete also. It’s now time to create details part. So same as above I have create a view with scaffold template details with customer model like following.

DetailView

Once we are done with creating view . It’s time to change the code for Details Action Result like following to return current customer detail.

public ActionResult Details(int id)
{
  using (var databaseContext = new Models.MyDataContext())
  {
      return View(databaseContext.Customer.Find(id));
  }
}

So that's it. We are done with all the stuff. So with Entity Framework code first. You can create basic CRUD application within 30 minutes without writing so much code. Hope you liked it. Stay tuned for more.. Till that Happy programming.

Shout it

kick it on DotNetKicks.com
Share:
Tuesday, July 5, 2011

CRUD Operation with ASP.NET MVC and EFCodeFirst Part-1

I have been playing with EFCodeFirst now and I found it very interesting with that you could write your application fast and easily. So I have decided to write series of blog posts for CRUD Operations using ASP.NET MVC 3 and EFCodeFirstCTP5.0 . You can very easily create CRUD within some minutes of code. So let’s start first thing is to create an ASP.NET MVC 3 application like following.

ASP.NETMVCApplication

Once you click OK. It will ask for the which type of View your are going to use. I have used Razor and HTML5 Semantic like following.

RazorView

Now once we have create a application Now its time to add EFCodeFirst reference via NuGet. So Go to the Library Package Manager –> Manage Nuget Package Manager. It will open up a dialog like following. Search EFCodeFirst and then it will fine EFCodeFirst package like following.

EFCodeFirst

Once you click Install it will add reference to your ASP.NET MVC Application like following.

EntityFrameworkRerence

So now all the things are set Its time to code now. So first I have Create my Table which is very simple table called Customer like I have used in previous post. For your reference I am putting the create table script below.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Customer](
   [CustomerId] [int] IDENTITY(1,1) NOT NULL,
   [FirstName] [nvarchar](50) NULL,
   [LastName] [nvarchar](50) NULL,
   [Address] [nvarchar](256) NULL,
   [City] [nvarchar](50) NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
   [CustomerId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY

Now let's create our entity class called customer like following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace CodeSimplified.Models
{
   public class Customer
   {
       public int CustomerId { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string Address { get; set; }
       public string City { get; set; }
   }
}

Now Its time to create a our datacontext class So I have created MyDataContext class inherited from the DBContextClass . In that I have defined my customer dbset and Also I override the default plural behaviour in ModelCreating Table. DBSet will tell datacontext which table we need to refer. So following is code for that.

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;

namespace CodeSimplified.Models
{
   public class MyDataContext:DbContext
   {
       public DbSet<Customer> Customer { get; set; }

       protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
       {
           modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
       }
   }
}

Now our database access stuff is ready now It’s time to create controller. So I have clicked controller folder and click on add new controller so add controller dialog box will appear like following.

AddController

It will create a controller class like following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CodeSimplified.Controllers
{
   public class CustomerController : Controller
   {
       //
       // GET: /Customer/

       public ActionResult Index()
       {
           return View();
       }

       //
       // GET: /Customer/Details/5

       public ActionResult Details(int id)
       {
           return View();
       }

       //
       // GET: /Customer/Create

       public ActionResult Create()
       {
           return View();
       }

       //
       // POST: /Customer/Create

       [HttpPost]
       public ActionResult Create(FormCollection collection)
       {
           try
           {
               // TODO: Add insert logic here

               return RedirectToAction("Index");
           }
           catch
           {
               return View();
           }
       }
      
       //
       // GET: /Customer/Edit/5

       public ActionResult Edit(int id)
       {
           return View();
       }

       //
       // POST: /Customer/Edit/5

       [HttpPost]
       public ActionResult Edit(int id, FormCollection collection)
       {
           try
           {
               // TODO: Add update logic here

               return RedirectToAction("Index");
           }
           catch
           {
               return View();
           }
       }

       //
       // GET: /Customer/Delete/5

       public ActionResult Delete(int id)
       {
           return View();
       }

       //
       // POST: /Customer/Delete/5

       [HttpPost]
       public ActionResult Delete(int id, FormCollection collection)
       {
           try
           {
               // TODO: Add delete logic here

               return RedirectToAction("Index");
           }
           catch
           {
               return View();
           }
       }
   }
}

Now once our controller is ready now its time to write some code for Index Action Result which we are going to have a list of customer. So I have changed Index Action Result like following to return customer view.

public ActionResult Index()
{
   using (var databaseContext=new Models.MyDataContext())
   {
       return View(databaseContext.Customer.ToList());
   }
}

Now let create a view from the controller. So Selected a view in right click Add View from Index Action Result. Here I have selected strongly typed view with Customer Model and selected list Template like following.

AddView

That’s it we are done with listing of the customer. Now its time to run our application and following is the output as expected.

Output

Hoped you like this…Stay tuned for more.. Till that happy programming.

Shout it

kick it on DotNetKicks.com
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews