开发者

Trying to deploy an Entity Framework Code First application without much luck? Best Deployment strategy?

Despite a few hiccups and a few workarounds, my MVC based Entity Framework (Code First) application is now complete and ready for deployment.

I originally tried developing through SQL Express, however, I had non stop problems with the Code First approach as I asked 开发者_开发技巧about here which made it completely unworkable.

So, in the end, I developed it following the majority of guidelines and used SQL Compact Edition. This has been absolutely brilliant for development - but - now it has come to deployment and I am stuck.

I have seen some people saying about generating the Schema from the .SDF file, however, there are differences and restrictions in Compact edition such as nvarchar being limited to a length of 4000, and I need max in my application.

So basically, what can I do?

In addition - but not essential - , I am going to be moving on to the next project shortly, It will involve heavy usage of items needing to be stored in a database that are longer than 4000 characters. Are there any better strategies now for development / Is it possible to use Code First with SQL Server Express or SQL Full (I have MSDN and willing to install/use anything that will help).


Here are my unofficial recommendations:

  • SQL CE is not a viable option for most production applications that are based on MVC (although I have used it in production services in rare cases).
  • I would try to avoid switching databases between development and production - i.e., don't test on SQL CE and deploy to SQL Express or something else.
  • I have never tried to open an MDF inside of Visual Studio - maybe I'm misunderstanding what you're saying here, but in general I'd recommend using the SQL Server-specific tools to manage databases: http://www.microsoft.com/download/en/search.aspx?q=sql+server+management+studio+express.
  • Regarding the other post, I would generally discourage using the AttachDBFilename portion of connection strings unless you need it for a specific purpose.
  • It sounds like you may want to review the available database initialization strategies: http://blog.oneunicorn.com/2011/03/31/configuring-database-initializers-in-a-config-file/.
  • There are lots of walkthroughs on our blog and the MVC MSDN site - if those don't work for you feel free to reach out to us from our blog and provide feedback on what we can do better!

Our blog: http://blogs.msdn.com/b/adonet/ MVC walkthroughs: http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part4-cs


On the one hand regarding deployment/migration you might want to take a look at http://exportsqlce.codeplex.com

On the other hand I've been checking Microsoft SQL Server Compact 4.0 Books Online and in principle there is no known issues with data types, although the limitation you mentioned for nvarchar is confirmed.

Finally in order to elaborate a strategy you might find interesting the Differences Between SQL Server Compact and SQL Server


You need to create a debug and a release specific web.config file:

  • In the release specific file you remove the connection string, so it creates a database for you.

  • In the debug specific file you keep the connection string.

However, I would suggest you to not use a connection string and use SQL Management Studio instead. Given that the Compact Edition does not support your requirement, this is a good time to switch...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜