Tag Archives: tips

Refreshing the LINQ to SQL DataContext by Clearing the Cache

LINQ to SQL DataContext can sometimes be difficult to deal with. Especially when combined with the use of stored procedures. For example, there is a case where I want to delete multiple records with a stored procedure rather than using the LINQ to SQL API for performance reason. After executing the stored procedure, the DataContext is not aware of the changes and still thinks that the entities are still there because the DataContext caches them. Hence, when I try to add another record using the same key, the DataContext throws an exception with the following message:

Cannot add an entity with a key that is already in use.

Logically, I want to refresh the DataContext memory so it will recheck the database. The provided DataContext.Refresh() method requires the original entity set to be sent which can be a problem. I don’t want to query the DataContext for the entities for performance reason, hence the stored procedure is used in the first place. So I have to find another way to refresh the DataContext or clear the cache without relying on the original entity set.

There is no official way to do it, but I stumbled on this blog post telling that there is a DataContext method called ClearCache() that can be used for that purpose. Unfortunately that method has internal modifier so you cannot call it from your code. But with a bit of reflection magic you can borrow the hidden power as follows:

	BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
	null, context, null);

After invoking the ClearCache() method, I can now successfully add new entities to the DataContext by reusing the keys from the deleted records.

WSS/SharePoint Extension 1.2 for Visual Studio 2008

Finally it’s out, get it while it’s hot.

Now you SharePoint developers no longer need to hesitate to upgrade to Visual Studio 2008 if you haven’t.

This will greatly help development of SharePoint-based solutions when you’re using Visual Studio 2008 by providing the following features:

Visual Studio 2008 Project Templates

  • Web Part
  • Team Site Definition
  • Blank Site Definition
  • List Definition
  • Empty SharePoint Project

Visual Studio 2008 Item Templates (items that can be added into an existing project)

  • Web Part
  • Custom Field
  • List Definition (with optional Event Receiver)
  • Content Type (with optional Event Receiver
  • Module
  • List Instance
  • List Event Handler
  • Template

SharePoint Solution Generator

  • This stand-alone program generates a Site Definition project from an existing SharePoint site. The program enables developers to use the browser and Microsoft Office SharePoint Designer to customize the content of their sites before creating code by using Visual Studio.

Installing the WSS/SharePoint extension on Windows XP/Vista

If you are using Windows XP/Vista and try to install the extension, it will display the following error:

The product can only be installed if Windows SharePoint Services 3.0 has been installed first.

Instead of replacing your OS with Windows 2003, launching a Virtual PC image preloaded with SharePoint, or trying to install SharePoint on Vista, you can simply create a registry entry to fool the extension installer as if you have installed WSS on your XP/Vista machine. Before following these simple steps, as with any registry modification, do so with caution at your own risk. You can create a registry backup if necessary.

Basically — under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0 registry key — you need to add the following string value: Sharepoint="Installed".

Here is the step-by-step instruction:

  1. Run regedit from command prompt or Start > Run.
  2. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0.
  3. If you cannot find the “12.0” folder, right click on the Web Server Extensions, select New > Key from the popup menu, and enter 12.0 as the new key name.
  4. Right click the “12.0” key/folder, select New > String Value from the popup menu, and enter Sharepoint as the name.
  5. Double click the newly created Sharepoint entry, and enter Installed as the value data.
  6. Now you can try to install the Sharepoint extension for VS 2008.

An easier way to do the above steps is to download the SharePointOnXP.reg file, extract, double click on the file. Then you can try to install the extension.

By the way, if you haven’t done so, you might also want to add SharePoint’s dlls to the GAC. Hence, Visual Studio won’t find troubles when compiling your SharePoint-based projects.

Five Things Today’s IT Workers Must Do

Bill Gates said the West is lacking talented IT workers. Representing the East, India is also heading towards a severe shortage of highly-skilled IT manpower. So now there is a great and broad chance for you, who live and breathe IT, to fill the gaps.

But keep in mind, that what the world is lacking is highly-talented IT workers, not average or even below average ones. Hence you must prepare and build yourself to be outstanding so the world chooses you.

Here are five quick tips for you so you won’t be just another IT worker:

1. Get Updated

The word “information” in IT is there for a reason. IT evolves very quickly. Things you learn today may be obsolete tomorrow. That’s why you must always update yourself with new information, knowledge, and skills if you want to keep up with others in IT industry.

2. Get Certified

You have built solutions in .NET Framework for 5 years. You think you are already a .NET expert, but does the market think so too? Larger companies usually recruit only certified workers. Some companies don’t ask if you are a graduate of Harvard, but they do ask if are a certified Java developer. Get certified and you will likely find your value much higher than before.

3. Get Connected

Gone are the days when a programmer sat in the corner, facing only his monitor and keyboard, typing cryptic codes only a computer could understand. Now you might still sit in the corner, facing your monitor and keyboard, but you must not only type cryptic codes. Instead get connected to other people. Share your knowledge, receive others. Today there are many ways to get connected even if you are not physically in touch. Online chatting, forums, blogs, wikis, and telephones to name a few.
Humans are social-beings. Naturally they enjoy doing things with others. Being an IT worker shouldn’t make you a nerd. Meeting other people lets you learn more and opens even more opportunities.

4. Predict the Market

Face it, there are way so many information and knowledge related to IT you won’t be able to digest them all even if you learn 24/7. Who cares if you are an ultra fast learner and able to learn at least 1 new technology everyday. There will be hundreds more the next day.

So be wise, learn only things you will need. Or better, learn only things the market will need. There are many languages to code in .NET: VB.NET, C#, Managed C++, J#, A#, APL, Chrome, NetCobol, F#, KPL, DotLisp, Ruby.NET, etc. Do you have to master them all? Will people seek you because you know a lot of programming languages? Predict the market. Find out what the market needs today or will need tomorrow. Master it and you will find yourself most welcomed.

5. Open Your Mind

Just because you are a developer in Microsoft platform doesn’t mean you only need to know the solution offered by Microsoft. There are a swarm of other vendors and technologies out there for you to explore. A vendor may be good in providing business solutions, but not in technical or other solutions. You can develop a solution using Oracle backend, Microsoft .NET framework as a frontend, and Linux in the middle for example. Do not limit yourself to certain vendor or technology. Your vendor and technology today might die tomorrow. And it is not uncommon in the IT industry.

Open your mind to innovation too. You don’t always have to think the way other people thinking. Think differently. Create new thinks. You could be the next Linus, Rasmus, Larry, or Bill, who knows.

Also open your mind to the world outside IT. Learn business, management, psychology, art, design or whatever knowledge relevant to what you want to achieve in the future. If you are a programmer but you don’t enjoy your job, don’t push yourself. Move to something else. You don’t have to make a radical maneuver. If you still want to be in IT industry but you hate coding, you can be a system analyst or database administrator for example. Or if you have a good managerial or business skill you can apply for a managerial position instead.

Enough for the tips, next things you will need are the perfect opportunity and a good luck.