Use DataContext to create schema in an existing blank database file?

Posted by jdk on Stack Overflow See other posts from Stack Overflow or by jdk
Published on 2010-05-13T17:47:23Z Indexed on 2010/05/13 18:24 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

With a DataContext and a blank file-based database that already exists, is it possible to write the Data Context classes (i.e. the ones I added to the designer) to create the db schema?

With a data context I only see the abilities to either:

  • create a new database file and have its structure created at the same time,
  • or to populate data into an existing database having preexisting schema.

I'm looking for a hybrid solution between those two worlds.

Update 1: My proof that a preexisting db is not compatible with the Data Context CreateDatabase() operation is this error

Database 'C:...\App_Data\IntermediateData.mdf' already exists. Choose a different database name.

based on this code

using (IntermediateClassesDataContext intermediateContext = new IntermediateClassesDataContext(_getIntermediateConn())) {
    intermediateContext.CreateDatabase();
}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about datacontext