7

A have an app with that uses an SQL database. The application is already released, but now I'm working on an update. In the update I've added an extra column in a table of my database.

I've create the database from my DMBL using DataContext.CreateDatabase() (not the other way around, as I found out to be the more common scenario later)

I there a facility in LINQ in which I can update my SQL database scheme?

2 Answers 2

1

No, sorry. I also would like to have such a facility. You have to upgrade your database by hand.

Here's the Method:

  • Create a Stored Procedure called something like "spGetDBVersion". This Procedure just returns an Integer of your current deployed Database version.
  • At startup/installation time check that procedure if it's result matches the version your Program expect.
  • If not -> execute update scripts in the right order. Example: if spGetDBVersion returns 2 and your application expects 5 then you have to execute Update_To_3.sql, Update_To_4.sql and Update_To_5.sql

Hint: After the initial release I never change my database schema with an tool. I always script that change and put that in my next update script.

Not that what you've asked, but it's a practicable solution.

An UpdateScript may look like this:

** PSEUDOCODE**

-- Update to version 2
alter table [MyTable] add newColumn int null
GO
update [MyTable] set [newColumn] = 0
GO
alter table [MyTable] change newColumn int not null
GO
alter procedure spGetDBVersion
as
begin
    select 2 as CurrentVersion
end
Sign up to request clarification or add additional context in comments.

Comments

0

If you change your table in the database you should delete the corresponding table from dbml file. Add it again and the dbml file should regenerate again , so your changes take effect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.