Wriju's BLOG

.NET, Cloud and everything

LINQ : From Basics to Query

Many of us are aware of LINQ today. LINQ is an amazing programming language feature. During my discussions I find a lot of myths around understanding. Here I have tried to demonstrate from some basics of C# 3.0 language enhancements to delegate, anonymous type, lambda expression and finally LINQ. How it has evolved. https://channel9.msdn.com/posts/LINQ-Evaluation-From-Basics-to-Implementation Namoskar!!!… Read more

Welcome to Microsoft Web Platform

    It is amazing to see so many Web Platform utilities are clubbed together in one single place. What you may need to develop website, are available here.   http://www.microsoft.com/web/default.aspx   If you go to downloads section http://www.microsoft.com/web/downloads/default.aspx you will get lot of things here, Namoskar!!!… Read more

NotifyIcon : Display Windows Form in System Tray

While talking to different people I get this question. And in Visual Studio it is very easy to do,   You need Windows Forms Application, then drag and drop NotifyIcon there. Set one icon with that control so that it is visible,   public partial class Form1 : Form {     public Form1()     {… Read more

LINQ to CSV : Getting data the way you want

Getting data from CSV is one of the mostly used business in applications/tools development. Here how we can do it in LINQ, You have a table called Emp with the below details, CREATE TABLE [dbo].[Emp](       [Id] [int] IDENTITY(1,1) NOT NULL,       [FirstName] [varchar](50) NOT NULL,       [LastName] [varchar](50) NULL,  CONSTRAINT [PK_Emp] PRIMARY KEY CLUSTERED… Read more

Setup and Deployment : Custom Action to Capture User Input

Purpose Users are allowed to pass Product Key while installing in .msi. During that we want to capture it for registration to avoid piracy. Challenges When we use “Customer Information” dialog in “Start” action, it has “SerialNumberTemplate”. But capturing information from there is really tough as mentioned in the article http://support.microsoft.com/kb/253683/en-us. So we have to… Read more

LINQ to XML : Understanding Annotations

Annotations are used for private use. It does not directly associated and known as Black Box in XML world. This can also be considered as meta tag. Below is an example on how it can be handled. I have created a sample Windows Applications and will try to capture my understanding. /// <summary> /// Class… Read more

LINQ – Uniformity All Over

I have spent a while with LINQ and still feel very new whenever I explore some new power. Here I am going to describe you how LINQ uniformly allows you write for the various types of data.   In-memory data source ++++++++++++++++ List<int> arrInt = new List<int> { 1, 2, 3, 4, 5, 6, 7,… Read more

Immediate Window is missing in Visual Studio Menu

  When you do not see “Immediate” window under Debug menu of Visual Studio you may get frustrated. But there is a quick way to get it when required,   Go to View > Other Windows > Command Window or press Ctrl+W, A   Then type immed. It will bring the Immediate Window.   And… Read more

ASP.NET 3.5 ListView and DataPager : Making RSS Reader

ASP.NET 3.5 comes with bundle of new data bound controls. Among them ListView and DataPager are the ones I am going talk here. To me ListView is the enhanced from of DataRepeater. It has got everything you might need to create an app with your HTML/CSS skill set. Today you often visit blogs and you… Read more

LINQ to SQL : Returning Scalar Value from Stored Procedure

In LINQ to SQL it is not that easy thing to achieve as compared to other features. Let us assume you have a Stored Procedure like, Case 1: With Output Parameter CREATE PROCEDURE [dbo].[GetEmployeeCount]       @OutVal DateTime OUTPUT AS BEGIN       SELECT @OutVal = GetDate() END You need to write code which will look like,… Read more

LINQ to SQL : Using ChangeSet for Audit Trail

Most of the transactional scenario, you may need to add the transaction to some table for ref. many apps does it for admin perspective.   Problem   You can do it in LINQ to SQL with ChangeSet but the problem is with Inserts. It does not give you the Identity field value until and unless… Read more

Choosing between ADO.NET Entity Framework and LINQ to SQL

As part of my day to job I come across a very common question from the developer community that one should be using LINQ to SQL (L2S) or ADO.NET Entity Framework (EF).   Earlier I have posted a blog containing the features http://blogs.msdn.com/wriju/archive/2009/01/05/choosing-between-linq-to-sql-and-entity-framework.aspx.    To me I feel very excited about EF as it has got… Read more

ADO.NET Data Services : Accessing Non-Relational Data

As you all know Astoria (Data Services) supports anything as backend. Not necessarily you need to have a Relational database to access data.   So if you talk about offline data like collection of an Object which may or may not come from an external entity (like XML) can also be exposed via Astoria.  … Read more

ADO.NET Data Services (Astoria) Resources

ADO.NET Entity Framework Resources http://msdn.microsoft.com/en-us/library/cc907912.aspx   Overview: ADO.NET Data Services http://msdn.microsoft.com/en-us/library/cc956153.aspx   ADO.NET Data Services Team Blog http://blogs.msdn.com/astoriateam/   Phani Raj’s Blog http://blogs.msdn.com/phaniraj/   Mike’s Podcast ADO.NET Data Services (VS08 Sp1 B1) – Surfacing Data ADO.NET Data Services (VS08 Sp1 B1) – Querying ADO.NET Data Services (VS08 Sp1 B1) – .NET Clients ADO.NET Data Services… Read more

ADO.NET Entity Framework : Paging EntitySQL

Paging in EntitySQL is really easy to achieve. You have got two important sub-clauses (or query operators) are available, SKIP and LIMIT.   So your paging EntitySQL query would ideally look like, “SELECT VALUE e FROM NorthwindEntities.Customers AS e ORDER BY e.CompanyName SKIP 10 LIMIT 10 “;   The most important part is that you… Read more

ADO.NET Entity Framework : Using EntityClient and EntitySQL

Using Entity Framework with LINQ is simple and fun stuff. But if you are concerned about the performance and comfortable writing ADO.NET like code then EntityClient is for you. It resides under System.Data.EntityClient namespace. If you are using it you also need to use the EntitySQL (not T-SQL) so the query will be little different…. Read more

ADO.NET Data Services Resources

Help yourself by exploring below resources on ADO.NET Data Services (aka "Project Astoria"). Data Platform Developer Center – Data Services page Data services conceptual documentation on MSDN Data services API reference documentation on MSDN Data services team blog Data services online forum (a place to ask us your data services related questions) Whitepaper: Using ADO.NET… Read more

LINQ to Entity : Supported and Unsupported Methods

There is a correction for this Post, so do I have changed the title. Thanks to Chris Love who pointed me the faults with earlier post, I got few question on some of the popular paging methods of LINQ which does not work on LINQ to Entity. This is by design and quite logical. In… Read more

CodeRush Xpress an amazing tool to work with Visual Studio 2008

Today I have came across a tool called CodeRush Xpress, a free AddIn which can be integrated with Visual Studio and make fun of the coding. This is a combined effort which DevExpress have had with Microsoft by leveraging the existing Visual Studio 2008 IDE. One scenario is very common to all of us when… Read more

ADO.NET Entity: LINQ to Entity with Relationship

Relationship and getting data from Entity Framework using Northwind database Simple Query   using (NorthwindEntities ctx = new NorthwindEntities()) {     var query = from o in ctx.Orders                 select o.OrderID;       foreach (var k in query)     {         Console.WriteLine(k);     } }   Now if you want to filter this with the… Read more

ADO.NET Entity: Insert Update and Delete with Relationship

Few days back I had written an article on Insert/Update/Delete for simple standalone tables at ADO.NET Entity: Insert Update and Delete. Now after that many of you had requested me to put article on how it works with relationship.   Here I will use a database created by me. There will be two tables connected… Read more

ADO.NET Entity: Insert Update and Delete

For small blogs, it requires more references and explanation, which sometimes are redundant. So I thought of writing single blog which is combination of topics more or less related to one thing.   I am exploring ADO.NET Entity Framework and have been trying things out there. Here I am planning to demonstrate how to do… Read more

Microsoft Project Code Named “Velocity”

“Velocity” is a distributed in-memory application cache platform for developing scalable, high-performance applications. “Velocity” can be used to cache any CLR object and provides access through simple APIs. The primary goals for “Velocity” are performance, scalability and availability. http://msdn.microsoft.com/en-us/data/cc655792.aspx Technical Articles Blog Microsoft Project Code Named “Velocity” Team Blog Forum Microsoft Project Code Named “Velocity”… Read more

Windows Forms – Enable Shortcut Key all over the Form

Windows Application and shortcut key are synonyms. People prefer to use shortcut keys for faster activity. Assume you are in a text box and you want to hit F5 to reload the form. You do not want to move your mouse cursor. So what you will be doing is that you will be adding “Key… Read more

Programmatically invoking the Live.com search

Live.com you need to automate that in your Windows application. You will use the WebBrowser control. This is a very powerful control and allows us to control things through DOM. Here is a small code which insert values to the live.com’s seach text box and clicks the “Go” button. I have created a windows forms… Read more

LINQ to SQL vs. ADO.NET – A Comparison

ADO.NET is our contemporary data access component and now we have written many applications. Now there has been a lot of talk on LINQ to SQL. So we are little skeptical about this component and trying to find some relation between existing ADO.NET technology.   Purpose of this post is to give some quick brief… Read more

How to copy my snippet in Visual Studio 2008

I use Visual Studio 2008 code snippet a lot when I write code for my presentation. It saves a lot of time and it is very elegant. But I used to struggle a lot while changing my demo machine. Because I had to repeat the same process again and again from Tools > Snippet Manager,… Read more

Visual Studio 2008 : How to zoom Class Diagram

During my demos I have noticed that Class Diagram in Visual Studio gives a very detailed view with lot of information. Now this is hard for people sitting at the back of the room to see what is there. It’s very easy, if you press “CTRL” then scroll the mouse, this will zoom in and… Read more

LINQ to SQL : Missing Manual are at MSDN

ADO.NET and LINQ to SQL Describes the relationship of ADO.NET and LINQ to SQL.   Analyzing LINQ to SQL Source Code Describes how to analyze LINQ to SQL mapping by generating and viewing source code from the Northwind sample database.   Customizing Insert, Update, and Delete Operations (LINQ to SQL) Describes how to add validation… Read more

LINQ to Entity : Querying data using ADO.NET Entity Framework

ADO.NET Entity Framework have evolved since we have released it first time. Now with the Visual Studio 2008 if you install the .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 you will get the fully functional version of ADO.NET Entity Framework. This is post Beta 3 release. To create a .edmx file you have… Read more

LINQ to SQL: Making it N-Tier

You can create your application use LINQ to SQL and make it N-Tier. Go ahead and watch out the MSDN Documents N-Tier and Remote Applications with LINQ to SQL LINQ to SQL N-Tier with ASP.NET LINQ to SQL N-Tier with Web Services LINQ to SQL with Tightly-Coupled Client-Server Applications Implementing Business Logic (LINQ to SQL)… Read more

LINQ to XML : Querying XML with Namespaces

This question arises in one of discussions. If you have a XML document with “xmlns” then LINQ to XML does not return any IEnumerable<T> J. This is strange but true for XPath and XQuery. There is a trick to get it done, Let us assume that you have a XML as follows, <?xml version=“1.0“ encoding=“utf-8“?>… Read more

Visual Studio 2008 Product Comparison

One of the mostly asked questions in the Visual Studio adopters group is “what am I not getting with my version?”. This probably sometimes leads to a business decision towards buying. Download the data sheet (from MSDN) One place for all your queries, at http://msdn.microsoft.com/en-us/vstudio/products/cc149003.aspx Namoskar!!!… Read more

LINQ : IEnumerable<T> and IQueryable<T>

IEnumerable<T> and IQueryable<T> are the two most used terms of any LINQ discussion. What I am trying to here is that I am trying to simplify the two interfaces depending on their behavior. In LINQ world we generally have few providers available within .NET Framework, like LINQ to Object, LINQ to SQL, LINQ to XML…. Read more

LINQ to SQL : FAQ Answer By Matt Warren

Wonderful composition of FAQ is available at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2769747&SiteID=1 by Matt Warren.   Q: How do I get default values from the database when inserting new entities? A: LINQ to SQL does not support using default values from the database.  The values in the entity at the time SubmitChanges is called are used instead.  You can… Read more

LINQ to XML : Modifying XML document

You have XML document now you want to modify that XML file using LINQ to XML. It is as easy as you generally modify any database column value.   Let us create a dummy XML stream,   //Create dummy XML to work var root = new XElement(“parent”,     from i in new int[] { 1,… Read more

LINQ to XML : Changing connectionString in app.config

When you create data bind application using wizard in Windows Forms application and connection string gets added to you settings file. Now you may be interested in changing that connection string but problems, 1)     The connection string in settings has an Application Scope so it is ReadOnly property. You modify and remove “ReadOnly” from .vb… Read more

The Developer Highway Code Free E Book

The Developer Highway Code, written by Paul Maher of DPE, is a concise handbook that captures and summarizes the key security engineering activities that should be an integral part of the software development process. This companion guide should be a must for any Developer, Architect, Tester etc. undertaking software development…The book is presented in easy… Read more

LINQ to XML : Adding Namespace quickly

I have written a post earlier on how to attach Namespaces. After reading my article someone complained about the redundancy of the code. I also realized the pain. I was reading the book C# 3.0 In a Nutshell. There I got a very elegant solution. Let me explain the scenario,   If you create a… Read more

LINQ to XML : Join Xml Data

Let’s say I have created two Xml files using LINQ to XML from Northwind database. I have taken two tables Category and Products and tried to join between two different files.   Category XML   <?xml version=“1.0“ encoding=“utf-8“?> <categories>   <category id=“1“>     <CategoryName>Beverages</CategoryName>   </category>   <category id=“2“>     <CategoryName>Condiments</CategoryName>   </category>   <category… Read more

LINQ to XML : Working with Prefixes

Based on my previous post on LINQ to XML : Working with Namespaces, if you want to add prefixes to your Xml things becomes little crazy. The trick is that you have to use XAttribute() to attach prefixes. So the Xml as below need the following code,     <pfx:root xmlns:pfx=“urn:mynamespace-com“>   <pfx:child /> </pfx:root>… Read more

LINQ to XML : Working with Namespaces

If you are working with complex real world XML then you have to deal with namespaces to disambiguate. There are several ways to implement namespaces in LINQ to XML. One is you can use pure string to add your namespace with each element declaration, like   <root>   <child /> </root>   To create the… Read more

LINQ to SQL Overview Video

Luca, the Microsoft Lead Program Manager, he is one of my favorite presenters. The way he demonstrate uninteresting thing and make fun of himself is one everyone should learn. Please enjoy the through presentation of LINQ to SQL at http://blogs.msdn.com/lucabol/archive/2008/03/03/linq-to-sql-overview-video.aspx   Namoskar!!!… Read more

C# 3.0 Query Expressions by Bruce Eckel and Jamie King

Bruce, a renowned author of the famous book “Thinking in Java” is now exploring C# 3.0. He wrote many other books on Ø       The Hands-On Java Seminar CD ROM (available on the Web site) Ø       Thinking in C++ (PH 1995; 2nd edition 2000, Volume 2 with Chuck Allison, 2003) Ø       C++ Inside & Out (Osborne/McGraw-Hill… Read more

LINQ to XML : Creating complete XML document

LINQ to XML API allows us to create complete XML document as expected with all the elements. So this X-DOM has everything as you expect.   Simple sample looks like,     XDocument doc = new XDocument(     new XDeclaration(“1.0”, “utf-16”, “true”),     new XProcessingInstruction(“test”, “value”),     new XComment(“This is comment by you”),     new… Read more

LINQ to XML : Creating XML from another XML

Based on my previous post if I have to filter the list of customers only in the country “US” and create another XML which may look like,   <?xml version=“1.0“ encoding=“utf-8“?> <usaCustomers>   <usaCustomer>     <title>Marketing Manager</title>     <name>Howard Snyder</name>   </usaCustomer>   <usaCustomer>     <title>Sales Representative</title>     <name>Yoshi Latimer</name>   </usaCustomer>   <usaCustomer>    … Read more

LINQ to XML : Creating complex XML through LINQ

We can generate hierarchical object graph in our memory though LINQ. To be more realistic we can bring data from relational database. So if we consider Northwind database and use LINQ to SQL to bring all the Customers and their Orders and Order Details the query would look like,     //LINQ to SQL way… Read more

LINQ to XML : Two important classes XElement and XAttribute

XElement and XAttribute are the two  very important classes available in System.Xml.Linq.dll assembly. Using these two classes you can do lot of things in the LINQ to XML world. I will show you step by step how,   For just an element   XElement _root = new XElement(“root”);   _root.Save(fileName);   And the output will… Read more

VB.NET 9.0: XML Literal

This is the one feature which can make VB.NET developers feel better than C# folks. I have seen people complaining about MS saying that MS has done lot for C# but not equally for VB.NET. One of the biggest was Refractoring. There are so many such. But this feature is just “SPELLBOUND” when I first… Read more

VB.NET 9.0: Lambda Expression Function

If you want to use Lambda Expression as reusable function, you need to use Func. By using the Func we are actually calling in-build delegate.   So if you write   Dim sqr As Func(Of Double, Double) = Function(x) x * x   Then you can use it in you application to get the square… Read more

VB.NET 9.0: Lambda Expression

In VB.NET 9.0 Lambda is one of the features we have here. Lambda expression is just another way to call Anonymous method/delegate.   Let’s look into a generic list of integers, and play with it,   Dim arrInt As New List(Of Integer)   For i As Integer = 1 To 10     arrInt.Add(i) Next  … Read more

VB.NET 9.0: Object and Array Initializers

Last week I was exploring VB.NET for the ISV demo delivery. Some findings I want to share with you. First the object and Array Initializers   Let’s suppose we have a class called Customer   Public Class Customer     Public Id As Integer     Public Name As String End Class   Now when you initialize… Read more

LINQ to SQL : Understanding Mapping

In LINQ to SQL you play with pure .NET objects and write your LINQ on top of that. But question might arise how this magic happens. Though we say that it is object, the question might arise in our mind that there has to be a mechanism through which it connects. Yes, there is. That… Read more

Sharing “var” across the method

One of the biggest limitation in “var” is that it cannot be shared across the methods. So if you are doing something using that keyword then you have to stick to the local. I was reading Alex’s Blog where he explained it very nicely,   Here is my implementation,   Create an Extension method  … Read more

LINQ to SQL and ADO.NET

Here I am going to compare the two technologies and point some missing areas.   Let us use the Northwind database and get the list of Customers from city London. The ADO.NET approach would be,   static void Main(string[] args) {     string sConn = @”ConnectionString”;     using (SqlConnection conn = new SqlConnection(sConn))     {… Read more

LINQ to SQL : What is DataContext.Translate Method

DataContext’s Translate method converts existing IDataReader to an IEnumerable<T>. This is very useful when you may need to run raw SQL Query though System.Data.Linq. I am getting few similarities with DataContext’s ExecuteQuery.   How Translate works +++++++++++++ Assuming I am using Northwind database.     using (NWDataContext db = new NWDataContext()) {     DbConnection conn… Read more

C# 3.0 : Useful keyword “var”

People complain about the keyword “var”. Especially, when we use it with the strict programming language like C# in .NET. Developers also complain about the readability part of it. I totally agree with them, but the scenarios where there will be no options but the “var” when it comes to on the fly projection of… Read more

C# 3.0 : Joining two in-memory collection through LINQ

LINQ allows us to join different collection source provided we are mapping with two properties with the same type. It is easy, it is quick and it is concise.     //Create Employee Class class Employee {     public int ID { get; set; }     public string Name { get; set; }     public… Read more

C# 3.0 Feature Articles

With this exciting release of .NET Framework 3.5 I have been exploring its magic and sharing the finding with you. Here I am compiling all of them together for indexing,   C# 3.0: Vote for the keyword “var”   C# 3.0 Features: Automatic Property C# 3.0 Features: Automatic Property (Part 2) C# 3.0 Features: Automatic… Read more

MSDN Virtual Labs : C# 3.0, Visual Basic 9.0, ASP.NET 3.5

Learn and for installation-free mode and get started with Visual Studio 2008.   MSDN Virtual Lab: Building Web Applications with Visual Studio 2008 MSDN Virtual Lab: What’s new in C# 3.0 MSDN Virtual Lab: What’s new in Visual Basic 9   Namoskar!!!… Read more

ADO.NET Entity Framework 3.5 Beta 3 Released today

Beta 3 of the ADO.NET Entity Framework, and a preview of ASP.NET 3.5 Extensions. Designed to make it even easier for developers to build data-centric applications and services regardless of the underlying data source, the ADO.NET Entity Framework is already gaining significant support from multiple database vendors and third-party providers, including Core Lab, Data Direct… Read more

C# 3.0 : Exploring Lambda Expression

I started playing with Lambda expression after the TechEd demo by Anders Hejlsberg. Couple of nice things I would like to share with you.   As there might be many definitions for Lambda expression but to me Lambda Expression is the concise way to write functional implementation for Anonymous Method. This is been used by… Read more

LINQ to SQL : Enabling .dbml file for WCF

LINQ to SQL is object relational model and .dbml file generates the class file for all kind of Create, read, update and delete (CRUD) through the mapping mechanism. Ideally this should allow us to enable it for WCF Service. But for that we have to manually add DataContract and DataMember attributes. We can use .dbml’s… Read more

Visual Studio 2008 Training Kit Videos on LINQ

Visual Studio 2008 Training Kit videos are now available on web. Get some real exciting presentations   VS2008 Training Kit: What’s new in C# 3.0? VS2008 Training Kit: What’s new in Visual Basic 9.0? VS2008 Training Kit: .NET Language Integrated Query (LINQ) VS2008 Training Kit: Using LINQ with Relational Data   For more detailed list… Read more

Visual Studio 2008 and LINQ Case Studies

Some of the early adopters case studies are now available,   Xcalia OpenNETCF Consulting Sogeti Group K2   Get some of the quotes from there,     LINQ is an object-oriented language and so fits perfectly with the philosophy of our product, which aims to make technical details of data access transparent to the developer…. Read more

Visual Studio 2008 Express ISO image download

As usual Express editions are free but this time you can take this and sit in a remote location and install Visual Studio with no Internet connections. Yes we can download offline .iso to avoid download & install pain. Please visit, http://www.microsoft.com/express/download/offline.aspx After downloading you can write them in DVD. This version includes all the… Read more

C# 3.0 : Evaluation of Lambda Expression to Language INtegrated Query (LINQ)

From code name “cool” to C# 3.0, it’s been a long journey for this amazing language with .NET Runtime. Here I am going to show you the evaluation step by step.   Let us assume we have generic list of integers and I need to find the even numbers from that list,   List<int> arrInt… Read more

LINQ to SQL: Working with hierarchical data

LINQ to SQL supports hierarchical data and you can easily create a query and get output from there. Let us take an example of Northwind database. Northwind has Category -> Products -> Order_Details tables. -> indicates one to many relationships here. So ideally for a Category can have multiple products and a product can have… Read more

LINQ to SQL : New method DataContext.GetCommand()

LINQ to SQL we can read the generated T_SQL query using DataContext.Log or SQLQueryVisualizer. But If you are working with WebProject the Log property not very much convenient as you have to use TextWriter to dump the generated T-SQL query.   In Orcas Beta 1 we had DataContext.GetQueryText which used to give us the generated… Read more

C# 3.0: Vote for the keyword “var”

You all probably know what is “var”. You might have a question why this new keyword is required in programming language like C#. One of the few strong reasons is to have an Anonymous Type stored in a variable. Whenever you have to initialize a type you have to mention the type before you give… Read more

LINQ to SQL Windows Form Binding Data Step by Step

LINQ to SQL designer in Visual Studio allows us to create mapped class using the drag and drop feature from Server Explorer. Now that is business object which ideally you could use as your datasource and from Visual Studio 2008. So let us have this step by step, Open your Visual Studio 2008 and create… Read more

LINQ to SQL : Some of the best BLOGs

Some of the best blogs on LINQ to SQL I found are available for great learning, Scott Guthrie The Famous LINQ TO SQL Series Part 1: Using LINQ to SQL Part 2: Defining our Data Model Classes Part 3: Querying our Database Part 4: Updating our Database Part 5: Binding UI using the ASP LinqDataSource… Read more

C# 3.0 : Anonymous Type and .NET Reflection Hand-in-Hand

Anonymous Type is nothing but the type which gets defined by CLR (not you). So that type is as rich as any other normal type. Probably the conventional way to find the components of an Anonymous Type through reflection would be clearer to us,   static void Main() {     //Anonymous Type     var anyType… Read more