将实体框架添加到asp mvc4 [英] Adding a Entity Framework to asp mvc4

查看:83
本文介绍了将实体框架添加到asp mvc4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我做错了,所以请耐心等待。我正在研究asp mvc4项目。我想为项目添加一个实体框架。所以我假设我将它添加到数据模型文件夹(它是从我的sql express中的数据库生成的)。现在我想创建一个DataAccess类来使用DatabaseEntities类读取和写入数据库,我把这个类放在模型文件夹中。但是为了使用这个类,我必须能够引用模型本身。我怎么做,我尝试''使用项目。'' ? ,没有数据模型选项!所以要么我把DataAccess类或模型放在错误的地方,要么我完全错过了某些东西或做了一些完全错误的事情?

I think i am doing this wrong, so please bear with me. I am working on asp mvc4 project. I want to add a entity framework to the project. So i presume i add it to the data models folder(it is generated from a database in my sql express). Now i want to create a DataAccess Class to read and write to the database using the DatabaseEntities Class, i put this class in the model folder. But in order to use this class i have to be able to reference the model itself. How do i do this, i try putting ''using project.'' ? , no Data Model option! So either i am putting the DataAccess Class or the Model in the wrong place or i have totally missed something or done something totally wrong?

推荐答案

解决方法是广告edmx到models文件夹并使用代码生成器生成类和数据上下文。但是现在我有一个新问题,当我去添加一个控制器时,它看不到我的数据上下文?!
The solution is to ad the edmx to the models folder and use a code generator to generate the classes and data context. However now i have a new problem in that when i go to add a controller it does not see my data context?!


这篇关于将实体框架添加到asp mvc4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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