0

ask your advices about this:

I am trying to create db compact edition, first time it was successfully with default dbName (ProjectName.dbContextName). But i decided to define my own name, and added in app.config in connectionString sections my connection string. After db was not created. From here MSDN Use code first with connection by convention i have done similar connection string:

 <connectionStrings>
    <add name="TestContext"
         providerName="System.Data.SqlServerCe.4.0"
         connectionString="Data Source=TestDb.sdf;"/>
  </connectionStrings>

(section name is equal to my dbcontext's name class.) Just to be sure before dbContext will be created:

Database.SetInitializer(new DropCreateDatabaseAlways<TestContext>());

Db still is not created. What am i doing wrong? Thanks in advance.

VahidN, i tried to add call of base class constructor, but doesn't work. Don't understand. It should be very easy. And as were aforementionted in ref above, if name of connection string in config section and name dbContext class are equal - object finds its connection string without problems.

Well, debugger says that conString is defined correctly (equal to string in config section), but actually db is not created - i can't find it nor in appfolder nor in sql server folders.

Ryan
  • 609
  • 6
  • 13

2 Answers2

0

You need to include the full namespace in the name of the connection-string. See here.

Something like this

<connectionStrings>
    <add name="YourNameSpace.TestContext"
         providerName="System.Data.SqlServerCe.4.0"
         connectionString="Data Source=TestDb.sdf;"/>
</connectionStrings>
SQB
  • 3,926
  • 2
  • 28
  • 49
Maarten
  • 22,527
  • 3
  • 47
  • 68
  • @Rayan: "editing" someone's answer is not for code-sharing. If you want to add more details to your question - edit your question and add code there! – quetzalcoatl Mar 03 '14 at 13:29
-1

Oh, sorry me for giving insufficient information, db was not created cause entities in dbContext was defined as List, not dbSet. inadvertency (

Ryan
  • 609
  • 6
  • 13