C# 在MVC项目中创建数据访问层的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17938610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to create a Data Access Layer in the MVC Project
提问by Vignesh
I have created an empty MVC project, in that I need to access database i am not using any entity framework ,just directly using codes. Here I have attached the snapshot of my project architecture in that u can see Data Access Layer folder, is it a good way to use the Data Access Layer in the same project or do we need to create a separate project for data access layer.
我创建了一个空的 MVC 项目,因为我需要访问数据库,我没有使用任何实体框架,只是直接使用代码。在这里我附上了我的项目架构的快照,你可以看到数据访问层文件夹,这是在同一个项目中使用数据访问层的好方法还是我们需要为数据访问层创建一个单独的项目。
Project Architecture Snapshot:
项目架构快照:
回答by Nithesh Narayanan
It is up to the architecture you choose. Basically in your MVC project your model communicate with the data.
这取决于您选择的架构。基本上在您的 MVC 项目中,您的模型与数据进行通信。
If you are using ADO
i would like to suggest move the model into separate class library
also DataAccess
into seperate class library which we are using in 3-tier
models.
如果您正在使用,ADO
我想建议将它model into separate class library
也DataAccess
移到我们在3-tier
模型中使用的单独的类库中。
Hence you can call data access from business logic
which are separated from the mvc project.
因此,您可以调用data access from business logic
与 mvc 项目分开的那些。
Some thing like this
像这样的事情
In the model you can use the BLL
在模型中,您可以使用 BLL
Or you can add the App_Data
folder and write a data access helper class and write the business logic in model itself. I would like to suggest separate it using the first method.
或者您可以添加App_Data
文件夹并编写数据访问助手类并在模型本身中编写业务逻辑。我想建议使用第一种方法将其分开。
回答by backtrack
Keep the data Access Layer as it is but through controller call the DataAccessLayer methods Because the view directly calls the corresponding controller. From that controller you can access the Data Access Layer but create the Class (models ) in the model Folder
保持数据访问层原样,但通过控制器调用 DataAccessLayer 方法,因为视图直接调用相应的控制器。从该控制器,您可以访问数据访问层,但在模型文件夹中创建类(模型)
回答by Prageeth godage
I am also face similar probelm.see following is help for you. http://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En
我也面临类似的problm.see以下对你有帮助。 http://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En
I use repository pattern and unit of work.But there you are redundancy coding via layers.the above link contain bit old one see is that help to you. don't forget to make a commet on this.thank you.
我使用存储库模式和工作单元。但是你通过层进行冗余编码。上面的链接包含一些旧的内容,看看对你有帮助。别忘了在这个问题上发表意见。谢谢。