1

I am learning EF.I have some classes of model and class that inherited from DbContext. I have intializer Initializer : DropCreateDatabaseIfModelChanges with empty method Seed.I call

 Database.SetInitializer<...Context>(new ...Initializer());

And I have set new add to connection strings

<add name="...Context" connectionString="Data Source=|DataDirectory|Temp.sdf" providerName="System.Data.SqlServerCe.4.0"/>

but I can't generate DB from this.App Data is empty. Please help me!Probably I forgot something?My method Seed I have left is empty but I don't think it's a trouble Thank u!

1
  • but I tried to design model of DB by tutorials Commented May 8, 2012 at 19:17

1 Answer 1

3

Setting a initializer is not enough. You need at least start a query.

In the moment you try to get data from your context, the process will start and if your database does not exists the will get created.

MyDbContext myDbContext = new MyDbContext();
var firstItemOfSomething = myDbContext.FirstItemOfSomething.FirstOrDefault(); 
Sign up to request clarification or add additional context in comments.

2 Comments

Hi!Thanks.It helps.Actually if u know can I watch all design of this generated DB in visual studio?
Yes you can open the Server Explorer and connect to your Database. If it was helpful, consider to accept my answer. But only if it was helpful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.