首先使用代码时,概念模型和相应的 .edmx 文件是否会自动创建?
我一直在关注 Apress 的新 Steve Sanderson MVC3 框架书籍,似乎根本没有提到从底层数据库创建概念模型/*.edmx 文件。只是基本的实体类和从 DbContext 派生的类,它将实体类映射到数据库中的表。然而,在书的中间,他突然谈到打开 *.edmx 文件并从数据库进行更新。
我没有完全遵循这些书,而是用它来帮助实现我自己的解决方案。在我的例子中,唯一真正的区别是我附加了一个 *.mdf 数据库,而不是创建带有 .dbo 扩展名的新数据库,并且我的数据库中有更多的表和关系,同样,每个表有更多的实体类。一切似乎正常,但没有 edmx 文件。
此外,输入所有实体类及其各自的属性也有点痛苦。是否有工具或其他东西可以从数据库创建这些 POCO 以便与 DbContext 一起使用?
I have been following the new Steve Sanderson MVC3 framework book from Apress and it seems there's no mention at all of creating the conceptual model/*.edmx file from the underlying database. Just basic entity classes and class deriving from DbContext which maps the entity classes to tables in database. However in the middle of the book he suddenly talks of opening the *.edmx file and updating from the database.
I am not following the books exactly, but rather using it to help implement my own solution. The only real difference in my case is that I attached an *.mdf database instead of creating new one with .dbo extension and that I have more tables and relationships in my database, likewise more entity classes for each table. Things seem to work, but there's no edmx file.
Also it was a bit of a pain in the azz typing up all the entity classes and their respective properties. Is there a tool or something, that can create these POCO's from the database for use with DbContext ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以阅读Code First:内部DbContext初始化 了解
DbContext
如何在没有 *.edmx 文件的情况下构建模型。EF 团队已创建 实体Framework Power Tools CTP1,它可以对数据库进行逆向工程以创建实体类和映射。您必须重命名该工具创建的一些导航属性名称,因为它们在大多数情况下没有意义。
You can read Code First: Inside DbContext Initialization to get an idea as to how
DbContext
builds up the model without *.edmx file.EF team has created Entity Framework Power Tools CTP1 which can reverse engineer your database to create the entity classes and mappings. You will have to rename some of the navigation property names that are created by the tool because they are not meaningful most of the time.