Wednesday, May 21, 2008

Windows Power Shell

Windows PowerShell

Windows PowerShell is advanced and extended command line interface shell and also it provides feature of scription language. It is available for following OS

* Windows XP SP2
* Windows Server 2003
* Windows Vista
* Built into Windows Server 2008 as optional feature

Also this shell is integrated with .NET Framework. So we can class and objects of .NET in our scripts. Windows PowerShell also provide Hosting Mechanism so it means you can embedded this Shell into your application and utilise the features and power of the PowerShell.


Sunday, May 11, 2008

Relations(Joins) in LINQ

Following is the sample which shows how can you use relations in the LINQ for query and get the data out of various objects

class Customer
public int CustomerID;
public string CustomerName;

class Order
public int OrderID;
public int CustomerID;
public DateTime OrderDate;

class CustomerOrders
public IEnumerable GetCustomerOrders()
Customer[] customers = {
new Customer{ CustomerID =1, CustomerName = "Pratap Singh"},
new Customer{ CustomerID =2, CustomerName = "Sikandar"},
new Customer{ CustomerID =3, CustomerName = "Ram Parsad Patnaik"}

Order[] orders = {
new Order{ CustomerID = 1, OrderID = 1 , OrderDate = Convert.ToDateTime("10/Apr/2004")},
new Order{ CustomerID = 1, OrderID = 2 , OrderDate = Convert.ToDateTime("3/Jan/2005")},
new Order{ CustomerID = 3, OrderID = 1 , OrderDate = Convert.ToDateTime("23/Mar/2006")},
new Order{ CustomerID = 2, OrderID = 1 , OrderDate = Convert.ToDateTime("14/Nov/2005")},
new Order{ CustomerID = 3, OrderID = 2 , OrderDate = Convert.ToDateTime("19/Dec/2008")}

var Query = from clist in customers
join oList in orders
on clist.CustomerID equals oList.CustomerID
select clist;

return Query;


Here in sample look at the join part of the LINQ join oList in orders on clist.CustomerID equals oList.CustomerID. In smiliar way you can create various joins and create a relational model in LINQ

Saturday, May 10, 2008

Local type inference

Local type inference is a language feature that allows you to define variables and use them without worrying about their true type. Local type inference is also interchangeably known as implicitly typed local variables. The burden is put on the respective language compiler to determine the type of a variable by inferring it from the expression assigned to the variable. The result is type safety while allowing you to write more relaxed code, which is required to support Language Integrated Query (LINQ).

Type inference can only be used within a local scope where its type can be inferred by the expression assignment. Type inference cannot be applied to any of the following:

* Cannot be a part of a member property declaration on a class, struct, or interface
* Cannot be used in a parameter list on a method
* Cannot be a return type for a method
* Cannot be defined without a right hand assignment expression
* Cannot reassign to be a different type once type has been inferred

namespace Sample.TypeInference
class Program
static void Main(string[] args)
int a = 5;
var b = a; // int
var x = 5.5M; // double
var s = "string"; // string
var l = s.Length; // int

Console.WriteLine("value of b is {0} and type is {1}",
b, b.GetType().ToString());
Console.WriteLine("type of x is {0}", x.GetType().ToString());
Console.WriteLine("type of s is {0}", s.GetType().ToString());
Console.WriteLine("type of l is {0}", l.GetType().ToString());


Sample of LINQ

In the following sample we will search for the customer having greater than the specified amount and will show there name in the message box

using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;

namespace SampleLinqApplication
public partial class CustomerDisplay : Form
public CustomerDisplay()

private void findCustomer_Click(object sender, EventArgs e)
LinqSample sample = new LinqSample();

class Customer
public string Name;
public string City;
public double Amount;

class LinqSample
public void FindCustomers()
Customer[] customers = {
new Customer { Name = "Anirudh", Amount = 9000, City = "Gurgaon" },
new Customer { Name = "Omkar Nath", Amount = 12202, City = "Nasik"},
new Customer { Name = "Peter", Amount = 123000, City = "Washington DC" },
new Customer { Name = "Madhav", Amount = 65553, City = "Bhopal"},
new Customer { Name = "Manpreet Singh", Amount = 789445, City = "Ludhiana"},
new Customer { Name = "Chin Yung", Amount = 5689, City = "Shanghai"}

var Query = from c in customers
where c.Amount > 10000
orderby c.Name
select c;

foreach (Customer cust in Query)

What is linq ?

Linq is a programing model which is introduced as new concept in the .Net Languages. It is also known as Language Integrated Query. Linq requires some of the extension for the complete support. These extension boosts the productivity also it shortens and gives meaning to syntax for better manipulation

Following is the linq query sample which returns the elements of array in ascending order and are greater then 5
var query = from v in AValues
where v > 5
orderby v ascending
select v;

Now we can retrieve the values from v with the help of the foreach loop in following manner

foreach(int vItem in v)

now the code of abive query will be converted by the compiler as the following

IEnumerable Query = AValues.Where(v => v > 5)
.OrderBy(v => v).Select(v => v);

Thursday, May 3, 2007

Microsoft .NET Framework 3.5 Beta 1

The Microsoft .NET Framework 3.5 Beta 1 is a preview release of the latest version of the .NET Framework. Many ISV’s, enterprises and Microsoft product teams are successfully building on the new features Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF) and Windows CardSpace in the .NET Framework 3.0. Microsoft plans to continue to invest in the .NET Framework developer platform and in support of existing users the .NET Framework 3.5 has a minimal number of breaking changes. So that existing applications built for .NET Framework 2.0 or .NET Framework 3.0 should continue to run without requiring changes. The .NET Framework 3.5 adds new features in several major technology areas; including:

  • Deep integration of Language Integrated Query (LINQ) and data awareness
  • ASP.NET AJAX for quickly creating more efficient, more interactive and highly-personalized Web experiences that work across all the most popular browsers
  • New web protocol support for building WCF services including AJAX, JSON, REST, POX, RSS, ATOM and several new WS-* standards
  • Full tooling support for WF, WCF and WPF including the new workflow-enabled services technology
  • New classes in the base class library (BCL) for the .NET Framework 3.5 address the most common customer requests.

.NET Framework 3.5 is planned to release at the end of 2007 and will ship with Visual Studio code name ”Orcas” and will also continue to be available for separate download from MSDN.

For more detail about the features being introduced in .NET Framework 3.5 and Visual Studio code name “Orcas”, click here

For more information about the .NET Framework, click here

Download Link:

Scripting .Net

Scripting Dot Net Applications (Source Microsoft Article Script Happens .NET)

New method of scripting is now avaliable in .Net . Script for the .NET Framework is the .NET equivalent of Windows Script, in that it provides a set of script engines that can be hosted within an application via a set of integration interfaces. Much in the same way as the Windows Script engines were part of the default install of Windows, the Script for the .NET Framework engines are included in the .NET Framework redistributable and are freely redistributable along with the rest of the .NET Framework. In this release of Script for the .NET Framework there are three script engines: Visual Basic® .NET, JScript® .NET and a compiled script loader engine. The loader engine is a script engine that can run compiled code but not compile