Jonas Stawski

Everything .NET and More

Recreating Entities with Linq To SQL

Be very careful when you need to recreate your entities with Linq to SQL. If I added a new column to the table and I needed to refresh my entity I used to remove it from the design and re add it again. This has worked for a while until now when all of a sudden I started getting errors in my production environment. What happened? I used to have the property DeleteOnNull on an association and when I removed the associated entity to recreate it it also removed the association. When I added the entity back to the diagram the association was recreated automatically, but the DeleteOnNull property was not set. Of course I realized what has happened a little too late and I found my self fixing a bug. How can you avoid this problem (besides having a bunch of unit tests)? I will say that if you need to refresh the entity, simply modify it manually with whatever changes you have made in the data base. That way you will not loose any property you might have added.

SP 1 of the .NET Framework 3.5 was recently released and having a refresh feature in the diagram would have been very nice

Happy Programming!

Comments (2) -

Hi Jonas,

Manually keeping the dbml in sync with the db is a mess, so I wrote an add-in for Visual Studio that adds "refresh" functionality to the L2S designer.

You can get a trial license and download the add-in from http://www.huagati.com/dbmltools/

Reply

I will give the add in a try

Reply

Add comment

biuquote
Loading