Saturday, June 7, 2008

Data Access with LINQ to SQL - Update

As with all new technologies, you continue to learn as you work with it.  Some of my thoughts have changed from my previous post on using LINQ to SQL.

After attending TechEd 2008 in Orlando this past week and speaking recently on this topic at the Austin Code Camp, I have a (what I think) is a better approach to doing data access with LINQ to SQL in an ASP.NET web project.  First, it is definitely my preference to separate all data context activity to the business and/or data tiers.

Some key things that I have learned along the way.  You will want to use the Attach(entity, true), which essentially tells LINQ to "trust me, the entity has changed, update the whole thing."  In order for this to work with an entity that has relational entities such as the Customer with the CustomerAddress, you must do one of the following things:

  1. Serialize and then deserialize the entity using the DataContractSerializer. This will be automatic if you are passing it over WCF, otherwise, you will need to write the code to essentially clone your entity.
  2. Use the DataLoadOptions to get the full entity graph when you pull down the original entity.

I've started storing my code up on Google Code.  Here's a link to download the latest bits.  If you aren't already an SVN user, just download TortoiseSVN-- trust me, it's easy.

Thursday, June 5, 2008

Slow Typing in Word and Outlook on your ThinkPad?

This was driving me absolutely crazy and hopefully it will help others (write a comment if it fixes your problem).  I was getting significant delay when I would type in Microsoft Word and Outlook and when it would and I could not figure out what the problem was.  I tried removing all my user settings, uninstalling/reinstalling Office.  Nothing worked.

Turns out that the problem wasn't with Office at all.  It was the Client Security - Password Manager program that comes pre-installed on ThinkPad laptops with fingerprint scanners.  Uninstall it and everything works like it should.