我可以使用什么DbContext项目与EF合作? [英] What DbContext project do I get to work with EF?

查看:127
本文介绍了我可以使用什么DbContext项目与EF合作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是实体框架的新手。我有来自NuGet的EF 4.2。现在我听说得到DbContext会很好。我已经进入扩展管理器,并尝试找到它,但我在那里看到约8。哪个是重?我不知道这是否重要,但我同时使用C#和VB.NET。此外,我不知道这是否重要,但是我正在使用一个数据优先模型,而不是一个代码优先或者模特儿模型来进行EF开发。

解决方案

在您的EDMX设计平面上,右键单击并选择添加代码生成项





从在线图库中选择ADO.NET DbContext Generator:





这将添加两个T4模板文件( *。tt ),并为您生成 DbContext 和实体类:





这是从 DbContext 为您自己的项目:




I'm new to entity framework. I've got EF 4.2, from NuGet. Now I'm hearing it would be good to get DbContext. I've got into the extension manager and tried finding it, but I see about 8 there. Which is the "righ" one? I don't know if this matters but I use both C# and VB.NET. Also, I don't know if this matters or not, but I'm using a data-first model, not a code-first or model-first models, for doing EF development.

解决方案

On your EDMX design surface, right-click and pick Add Code-Generation Item:

Pick the ADO.NET DbContext Generator from the online gallery:

This adds two T4 template files (*.tt) in your solution explorer, and generates the DbContext and the entity classes for you:

And this is the resulting class derived from DbContext for your own project:

这篇关于我可以使用什么DbContext项目与EF合作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆