0

I have local sqlite db near my *.exe file and I need that the core of migrations will generate (by Update-database command) database in this place. Now I'm using only database name as parameter of DbContext constructor, but db is not generated near my *.exe (I think because it is performed in another process).

How I can do it?

I've found the solution here, but it's not good... How to create dynamic database in entity framework with specified path?

Thanks.

7
  • Please let me know if I described my issue unclear. Commented Sep 9, 2015 at 11:33
  • Here is a thread on SQLite creation that may help: stackoverflow.com/questions/22174212/… Commented Sep 9, 2015 at 12:43
  • If SQLite doesn't support db initialization I can use default local db, but I need have db near *.exe file... Commented Sep 9, 2015 at 12:50
  • Ok, I think I need to use default (SqlServer) local db to avoid any issues with EF core but I still don't know how I can generate db near .exe Commented Sep 9, 2015 at 13:36
  • If you are going to use localdb you can specify a path in the connection string. Be aware it is intended to only be used for development purposes. Maybe consider SQL Express? blogs.msdn.com/b/sqlexpress/archive/2011/07/12/… Commented Sep 9, 2015 at 14:51

1 Answer 1

2

In my WindowsForms application with SQL Server CE I do this steps:

1) In app.config configure your connections string like this (add "|DataDirectory|")

.... connectionString="Data Source=|DataDirectory|yourDatabase.sdf" />

2) In constructor of Configuration() class insert path to location with your database

internal sealed class Configuration : DbMigrationsConfiguration<DataContext>
{
    public Configuration()
    {
        AppDomain.CurrentDomain.SetData("DataDirectory", @"your_path");
    } 
...
}

After "update-database" command EF will update database in this path

Sign up to request clarification or add additional context in comments.

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.