LINQ2SQL – Updating Stored Procedures (VS2008)

October 6, 2011

I’m currently working on a project using LINQ2SQL with stored procedures. I quickly ended up with a problem that rang bells, remdinding me of when I last worked with LINQ2SQL and SPROCS (Some time back), that problem being that once a SPROC has been added to the DataContext, its not possible to (easily) update the output of it, or the signiture.

I remember my previous fix to this was to rename the stored procedure and re-add it (Deleting the old one from the DataContext). This works fine on smaller systems with 1-2 developers – Renaming a Stored Procedure on a larger system may not alwasy be an option.

So, here is a better fix for this scenario – Its not elegant, and still irritating, but it does work…
(Note: Only tested in Visual Studio 2008 – I dont know if this problem exists in Visual Studio 2010)

  1. Delete stored proc from DBML file
  2. Close DBML file
  3. Right click on DBML in solution explorer – Open with > XML Editor then Save it (No need to make any changes)
  4. Open DBML file as normal
  5. Right click on SPROC in server explorer > refresh (To ensure Visual Studio knows about the changes to your stored procedure)
  6. Drag and Drop SPROC to your DBML to re-add it with the new signature/return type
  7. Hoorah!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: