ASP.NET MVC中的数据库上下文类的目的是什么 [英] What is the purpose of a db context class in asp.net mvc

查看:395
本文介绍了ASP.NET MVC中的数据库上下文类的目的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC的新手,并且已经做了一些教程来掌握它,但是在其中一些教程中,我遇到了一个带有DbContext类

I'm new to MVC and have done some tutorials to get the hang of it, but in some of these tutorials I have come across an example with a DbContext class asp.net mvc5 with EF6 tutorial

我尝试研究有关DbContext类的信息,但无法获得任何使我更明智的信息!我所能找到的只是更多相同的教程而几乎没有信息,我还在msdn

I have tried researching information on DbContext Class but was unable to get any information that made me any the wiser! all I could find are more of the same tutorials with little information I also looked up the class on msdn DbContext Class.

我之前没有使用db上下文类来完成本教程,并且工作正常,我的问题是我是否需要使用上下文类,以及使用DbContext类的优点是什么?

I have done previous tutorials without a db context class and it works fine and my question is do I need to use a context class, and what are the advantages of using a DbContext Class?

任何帮助将不胜感激.

推荐答案

我首先要说DbContext类与

I would first say that the DbContext class relates to Entity Framework (EF), but then the question tags would suggest you figured that much out yourself. In typical usage, deriving from the DbContext class is simply the way to incorporate EF-based data access into your application. The class that derives from DbContext is, in essence, the data access layer of your application.

换句话说,如果要使用Entity Framework进行数据访问,则DbContext是您想要的.

So to put it the other way around, if you want to do data access with Entity Framework, DbContext is what you want.

这篇关于ASP.NET MVC中的数据库上下文类的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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