简体   繁体   English

映射和sql数据库创建

[英]Mapping and sql database creation

I started a project and use Entity Framework 5. Now I created a database on my SQL Server Express with all tables. 我开始一个项目并使用Entity Framework5。现在,我在SQL Server Express上创建了一个包含所有表的数据库。 Further I created the DbContext with a fluent mapping. 此外,我使用流畅的映射创建了DbContext

What is better, the fluent mappings or the .edmx mapping files? 更好的流利的映射或.edmx映射文件?

The database is now on the SQL Server but I want support also SQL local db. 该数据库现在位于SQL Server上,但我还希望支持SQL本地数据库。

Is there a way to tell the EF that I want to use a SQL local db? 有没有办法告诉EF我要使用SQL本地数据库?

Should I ship the whole database within the setup or better to create the database on startup of my application? 我应该在安装程序中运送整个数据库还是更好地在启动应用程序时创建数据库? How can I use EF to create the database (SQL server or SQL local db)? 如何使用EF创建数据库(SQL Server或SQL本地db)?

Every useful help would be appreciated. 每个有用的帮助将不胜感激。

If you are using EF5 I would stay away from edmx. 如果您使用的是EF5,我将远离edmx。 You could reverse engineer your model from database using Entity Framework Power Tools. 您可以使用Entity Framework Power Tools从数据库对模型进行逆向工程。 Than you can customize your model using either Data Annotations or fluent mappings. 比起您可以使用“数据注释”或流利的映射自定义模型。

If you use EF5 code first it can create database automatically for you if not present, however that would not work very well on subsequent upgrades (it can recreate database but then you will use or your existing data). 如果首先使用EF5代码,它可以自动为您创建数据库(如果不存在),但是在随后的升级中效果不佳(可以重新创建数据库,但是您将使用或现有的数据)。 The options you could use, is either EF migrations, where you can specify in fluent-like languagage the modifications that were made to your database or use Database Project in Visual Studio, where you can store all your schema in source control and then generate database upgrade scripts betweeen releases. 您可以使用的选项是EF迁移,您可以在其中以流利的语言指定对数据库所做的修改,也可以使用Visual Studio中的数据库项目,您可以在其中将所有架构存储在源代码管理中,然后生成数据库在发行版之间升级脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM