EntityFramework 4.3 - 在没有 ObjectContext 的情况下从数据库创建 DbContext?

发布于 2025-01-07 23:44:54 字数 520 浏览 5 评论 0原文

按照 http://msdn.microsoft.com/en-us/data/gg715119 上的教程进行操作 它描述了将 EDMX 实体数据模型添加到我的解决方案中(它会生成混乱的模型,包括来自我的数据库的 ObjectContext),并且之后本教程会生成一个DbContext 通过单击 EDMX 设计器上的“添加项目...”(因为这是生成 DbContext 选项可用的位置)。

如果我想使用 EF 4.3 DbContext,这是要走的路吗?仅使用 DbContext 时是否可以以某种方式从我的数据库创建模型?

我真的不希望在我的解决方案中使用带有 EDMX 文件的 ObjectContext 。只是 .tt 文件。 这可能吗?

Following the tutorial on http://msdn.microsoft.com/en-us/data/gg715119 it describes adding an EDMX Entity Data Model to my solution (which generates cluttered models including ObjectContext from my db) and after that the tutorial generates a DbContext by clicking "Add item..." on the EDMX designer (because this is where the option Generate DbContext is available).

Is this the way to go if I want to work with EF 4.3 DbContext? Isn't it possible somehow to create a model from my database while only using DbContext?

I don't really want the ObjectContext with EDMX file in my solution. Just the .tt files. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

摘星┃星的人 2025-01-14 23:44:54

如果您想使用 DbContext(或任何其他模板),您必须首先关闭生成 ObjectContext 的默认代码生成 - 在 EDMX 属性窗口中删除用于代码生成的自定义工具。

If you want to use DbContext (or any other template) you have to first turn off default code generation which produces ObjectContext - in EDMX property window remove custom tool for code generation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文