Many times we need to get the Public key token for a strongly named assembly in .NET. FAQ on that “how to get the public key token?”. Answer is very simple use the .NET Framework tools sn.exe. So open the Visual Studio 2008 Command Prompt and then point to the dll’s folder you want to get the public key,
Use the following command,
sn –T myDLL.dll
This will give you the public key token. Remember one thing this only works if the assembly has to be strongly signed.
C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T EdmGen.exe
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.
Public key token is b77a5c561934e089
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 on some major differences between ADO.Net and LINQ to SQL. I have not used 100% code as this is just to give an idea. The database I have used here is Northwind (SQL Server 2000 Sample database).
Establishing connection between database and application,
using(SqlConnection conn = new SqlConnection("Connection String"))
LINQ to SQL
You create a .dbml file and give a name (assume “NW.dml”). Then there will be a DataContext class created. So you need to initialize the instance of an object.
NWDataContext db = new NWDataContext("Connection String");
You do not need to call any Open() method. Datacontext handles well the open and close method.
Getting data from database,
using (SqlCommand comm = new SqlCommand("Select * from Customers"))
SqlDataReader reader = comm.ExecuteReader();
DataTable dt = new DataTable("New Table");
LINQ to SQL
using (NorthwindDataContext db = new NorthwindDataContext())
//You can also use "var" at "IEnumerable<Customer>"
IEnumerable<Customer> custs = from c in db.Customers
foreach (Customer c in custs)
WOW!!! I have received comment from our Senior Program Manager Dinesh Kulkarni from LINQ to SQL team when I requested him to visit my blog. He mentioned,
DataTable provides you a cache that can be re-enumerated without DB roundtrip while LINQ to SQL results need to be explicitly cached with something like a ToList()/ToArray(). Identity caching in DataContext aside, the L2S code is closer to enumerating a DataReader. Although DataReader does not allow you to re-enumerate and requires another ExecuteReader, the impact of reenumerating L2S query is the same – another roundtrip to DB.
Inserting into the database,
using(SqlConnection conn = new SqlConnection())
SqlCommand comm = new SqlCommand("INSERT INTO...", conn);
//Create a new object
Customer c = new Customer();
c.CustomerID = "ABCDE";
//.... add all the properties you need to add while inserting
//Add it to the collection
//Save the changes to the database
Same as Scenario 3
//Get the object from database
Customer cust = (from c in db.Customers where c.CustomerID == "ALFKI" select c).First();
//Update the exsisting value
cust.CompanyName = "I do not know?";
Deleting records from the database,
//Remove it from collection
Executing stored proc which returns record(s),
using (SqlCommand comm = new SqlCommand("SalesByCategory", conn))
comm.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = comm.ExecuteReader();
In LINQ to SQL it becomes metod as you drag and drop it to .dbml file,
var outPut = db.SalesByCategory("SeaFood", "1998");
Performance of LINQ to SQL and ADO.NET
LINQ to SQL Performance Part 1
LINQ to SQL Performance Part 2
LINQ to SQL Performance Part 3
LINQ to SQL Performance Part 4
LINQ to SQL Performance Part 5
There are a many to discuss. Hope you have enjoyed it.
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 Down” event to the text box. But if you are in a different text box or in a button that will not work. So you will add “Key Down” event to your form.
But you need to enable a property to work it properly and that’s the trick.
private void Form1_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode == Keys.F5)
But golden trick is, in the property window of the Form make the following changes
KeyPreview = True
What happens if you install you Visual Studio then realize that you need IIS for you application to test and run. We often do this. I have seen people uninstalling Visual Studio and then installing it again after IIS to make sure ASP.NET works fine.
Wow!! There is an easy way to do it,
Open the command prompt for Visual Studio 2008. Run the following command
Install this version of ASP.NET and update scriptmaps at the IIS metabase root and for all scriptmaps below the root. Existing scriptmaps of lower version are upgraded to
this version. (this is from product documentation help text)
You can also check if the specific ASP.Net version is already attached with IIS by using –lv.
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 template in Visual Studio 2008,
Project > Add New Item
After creating the .edmx file, write the below query,
using (ObjectContext objC = new ObjectContext("name=NorthwindEntities"))
ObjectQuery<Customers> custs =
foreach (Customers cust in custs)
Note that this returns Object ObjectQuery<T> which implements IQueryable<T>, which means it will also allow you to write LINQ and this LINQ supports external source. Meaning it will translate the code to T-SQL (if you use MS SQL Server database).
I feel more comfortable if I use LINQ,
var custs = from c in
where c.City == "London"
Now this is already strongly typed and I do not have to use ObjectContext and ObjectQuery anymore.
So my pure LINQ to Entity will look like,
using (NorthwindEntities db = new NorthwindEntities())
var custs = from c in db.Customers
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 out the class diagram.
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 code and other customizations.
Data Binding (LINQ to SQL)
Describes how LINQ to SQL uses IListSource to support data binding.
Inheritance Support (LINQ to SQL)
Describes the role of inheritance in the LINQ to SQL object model, and how to use related operators in your queries.
Local Method Calls (LINQ to SQL)
Describes LINQ to SQL support for local method calls.
Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL)
Provides detailed information for multi-tier applications that use LINQ to SQL.
Object Identity (LINQ to SQL)
Describes object identity in the LINQ to SQL object model, and explains how this feature differs from object identity in a database.
The LINQ to SQL Object Model
Describes the object model and its relationship to the relational data model.
Object States and Change-Tracking (LINQ to SQL)
Provides detailed information about how LINQ to SQL tracks changes.
Optimistic Concurrency Overview (LINQ to SQL)
Describes optimistic concurrency and defines terms.
Query Concepts in LINQ to SQL
Describes aspects of queries in LINQ to SQL that differ from queries in LINQ.
Security in LINQ to SQL
Describes the correct approach to security in database connections.
Serialization (LINQ to SQL)
Describes the serialization process in LINQ to SQL applications.
Stored Procedures (LINQ to SQL)
Describes how to map stored procedures at design time and how to call them from your application.
Transactions (LINQ to SQL)
Outlines the three models of transaction that LINQ to SQL supports.
Type System Mismatches (LINQ to SQL)
Describes the challenges of mingling different type systems.
User-Defined Functions (LINQ to SQL)
Describes how to map user-defined functions at design time and how to call them from your application.
When I show demo using my desktop I often come across to the scenarios where things are very small. I was using Windows Magnifier. I found this tool later and this is very helpful. This tool was created by Microsoft Technical Fellow, Mark Russinovich.
Ø ZoomIt runs on System Tray
Ø Allows you to use configurable shortcut key
This is very lightweight and simple tool. You will enjoy if you use them.
Problem with LINQ
to SQL? Want to troubleshoot?
List of FAQs are at
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, I find it very inconvenient if you have many snippets.
There is an elegant way to do that, under
C:\Documents and Settings\<<logged in user>>\My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets
Copy the files from your source machine and paste them to the destination machine’s same folder. You will get all the snippets. You do not have to use Snippet Manager anymore to upload snippet.
"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.
Microsoft Project Code Named "Velocity" Team Blog
Microsoft Project Code Named “Velocity”
Microsoft Project Code Named “Velocity” on Code Gallery
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 application and added a WebBrowser control named “webBrowser1”.
//Set the value to the Search text box
webBrowser1.Document.GetElementById("sb_form_q").SetAttribute("value", "Wriju's BLOG");
//Now click the button
//this actually submits the one and only one form
//So you need to do that
Wow experience!!! 200+ posts on MSDN with millions of hits it’s a great pleasure being at Microsoft with additional takeaways. I never thought in my life that I would be blogging. I had a dream that one day I will become writer (was not sure on what though). Blogging is a great tool to give values back to community for people with less power (like me or introvert).
My journey has been always a pleasure (be it blogging or 5 day long on-road cross country cargo truck travel). But my greatest takeaway was when my blog was in MSDN C# Home page. Charlie was kind enough to put my blog in the same list with Scott Guthrie (http://weblogs.asp.net/scottgu/). I never had a clue on how Scott manages to write blog so regularly.
You may find some of my selected and relevant past posts are at Charlie’s blog at Community Convergence and my journey stared from Community Convergence XXXV. I have no words to say thanks to Charlie (our very own C# Community Program Manager). Many people have encouraged me in many ways, Program managers, friends, Microsoft Partners (with whom I work professionally), my super technical Microsoft teammates, people from everywhere over the web. Some of them have added my blog to their favorite list (priceless to me always).
There are many things I have planned to write. I am a lazy person, so I need to be focused and keep on contributing to my blog.
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.
I am not a good writer, but I love many things at Microsoft.