我们可以用Razor在MVC3中做DBContext吗? [英] Can we do the DBContext in MVC3 with Razor?

查看:84
本文介绍了我们可以用Razor在MVC3中做DBContext吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过在Web.config中定义ConnectionString来使用MVC3中的DBContext连接到数据库吗?



如果可能,任何人都可以提供一些链接吗?

解决方案

简短的回答是肯定的。您可以在控制器操作方法中使用Entity Framework:



http://msdn.microsoft.com/en-gb/data/ee712907 [ ^ ]



您使用的视图引擎根本不会影响您的数据层。这是使用MVC的好处之一。


请参阅此链接...

体系结构指南:ASP.NET,MVC3,实体框架,代码优先与现有数据库以及更多...... [ ^

Can I connect to the DB using DBContext in MVC3 by defining the ConnectionString in Web.config?

If possible can anyone provide me some links too?

解决方案

The short answer is yes. You can use Entity Framework in your controller actions methods:

http://msdn.microsoft.com/en-gb/data/ee712907[^]

The view engine you use has no bearing on your data layer at all. It''s one of the benefits of using MVC.


Refer this link...
Architecture Guide: ASP.NET, MVC3, Entity Framework, Code-First with existing Database and few more..[^]


这篇关于我们可以用Razor在MVC3中做DBContext吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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