[英]Entity Framework & SQL Server 2008 Express
I'm totally new to Entity Framework and have done some reading, and as a test I have put together a very brief test framework with just two small Entities. 我是Entity Framework的新手,并且已经读了一些书,作为测试,我仅用两个小实体组成了一个非常简短的测试框架。 I then right clicked and selected "Generate Database from Model" which takes me to the SQL Connections page.
然后,我右键单击并选择“从模型生成数据库”,该页面将我带到“ SQL连接”页面。 However, none of the previous connections I have used appear in the drop down list, and when I select Create New Connection I only have the options to use 'SQL Server Compact 3.5' or 'SQL Server Database File'.
但是,我以前使用的任何连接都不会出现在下拉列表中,并且当我选择“创建新连接”时,我只有使用“ SQL Server Compact 3.5”或“ SQL Server数据库文件”的选项。
I have come across this before with SQL Express and the work around is to create my own Connection String to access the required Database. 我之前使用SQL Express遇到过这种情况,解决方法是创建自己的连接字符串以访问所需的数据库。 However, with me using Entity Framework to create the database, it is impossible to write an appropraite connetion string.
但是,使用我使用Entity Framework创建数据库时,不可能编写适当的连接字符串。
I therefore seem to be in a Catch 22 situation. 因此,我似乎处于Catch 22的情况。
Anyone come across this or can point out what I'm doing wrong. 任何人都会遇到这个问题,或者可以指出我做错了什么。 Like I said I'm totally new to EF so I apologise if this is a very basic question.
就像我说的那样,我对EF完全陌生,因此,如果这是一个非常基本的问题,我深表歉意。
Unless you want to use a database file in a user instance, you need to either use SQL Management Studio Express, or use the SQLCMD command line tool to create the database. 除非要在用户实例中使用数据库文件,否则需要使用SQL Management Studio Express或使用SQLCMD命令行工具来创建数据库。 I would recommend SQL Management Studio Express as it is easy to learn in my opinion.
我建议使用SQL Management Studio Express,因为我认为它很容易学习。
The Entity Framework tools are intended to be used to create the database schema , not the database itself. 实体框架工具旨在用于创建数据库架构 ,而不是数据库本身。 You still need to define the file groups, security information, and other basics of creating and configuring a blank database.
您仍然需要定义文件组,安全性信息以及创建和配置空白数据库的其他基础知识。
See this Q/A for appropriate links: 有关适当的链接,请参见此问题解答:
How to create DB in SQL Express using SQL commands? 如何使用SQL命令在SQL Express中创建数据库?
Thanks @psuedocoder, your assistance helped me resolve the problem. 感谢@psuedocoder,您的帮助帮助我解决了问题。 The answer in the end was simple, but not intuitive to me, hence my difficulty.
最后的答案很简单,但对我来说却不直观,因此很困难。 I thought some elaboration on the answer might help others who are equally new to Entity Framework as me.
我认为对答案的详细阐述可能会对像我一样对Entity Framework同样陌生的其他人有所帮助。
From Visual Studio 从Visual Studio
As @psuedocoder states this does not actually create the database in SQL Server, but it does create an object in your VS soluton which contains the TSQL script required in order to create your database. 正如@psuedocoder指出的那样,这实际上并没有在SQL Server中创建数据库,但确实在VS解决方案中创建了一个对象,该对象包含创建数据库所需的TSQL脚本。
From SSMS 从SSMS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.