0

I have a little problem with my database. I want to create the database using Entity Framework (code-first) but all tutorials showing how to do so do it in a console application using something like this in their main class method:

exampleDb.Example.Add(); 
exampleDb.SaveChanges();

But I want to create my database in a WPF application. What should I do?

thanks, mm.

0

1 Answer 1

1

Find your App.xaml.cs file, it should be under App.xaml, override OnStartup, then init your database.

protected override void OnStartup(StartupEventArgs e)
{   
    base.OnStartup(e);  

    exampleDb.Example.Add(); 
    exampleDb.SaveChanges();
}
Sign up to request clarification or add additional context in comments.

1 Comment

It works. I used migrations too and finally created my db.

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.