2

Does Winforms support Code-First Entity Framework. I know ASP.net MVC support it, but how about Winforms?

I create connection string in app.config:

<connectionStrings>
    <add name ="Transaction" connectionString="DataSource=|DataDirectory|Transaction.sdf" providerName="System.Data.SqlServerCe.4.0"/>
  </connectionStrings>

I also create Transaction class with all the fields, and Transaction DbContext, but when I compile, it does not create the sdf file automatically.

Thank you.

UPDATE I added this two lines, but is still not working:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<EmvTransactions>());

It gives me this error:

> An error occurred while updating the entries. See the inner exception
> for details.
9
  • I think here is your answer - stackoverflow.com/questions/4838217/… Commented Jul 25, 2012 at 14:07
  • You need to call an Initialize and install a DropDatabaseifChanged thing. @Giedrius - normally from App_Start() in MVC. Commented Jul 25, 2012 at 14:10
  • @Henk Holterman I am not using ASP.net MVC, I am using Winforms. Commented Jul 25, 2012 at 14:14
  • Then you need to call it somewhere else. I was responding to an older comment. Commented Jul 25, 2012 at 14:25
  • 2
    Maybe you could write your solution as answer (or delete the question). Commented Jul 27, 2012 at 12:36

0

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.