[英]C# MVC Structuring a project with SQL Server stored procedures
I'm a .net virgin but have been assigned a project using C# abd ASP.NET MVC (using visual studio express 2013 for web). 我是.net处女,但已使用C#Abd ASP.NET MVC(使用Visual Studio Express 2013 for Web)分配了一个项目。 I need the project to integrate with the client's SQL Server database. 我需要该项目与客户端的SQL Server数据库集成。
They have stored procedures set up in the database to get and set data which does everything I need, but am unable to find much in the way of information on how I should be structuring my project. 他们已经在数据库中设置了存储过程,以获取和设置满足我所需的所有数据,但是无法找到有关如何构造项目的大量信息。
If I was to bypass the stored procedures, I could just create a class for each of the tables but am struggling to get my head around how I should be structuring the project to use the stored procedures. 如果我要绕过存储过程,则可以为每个表创建一个类,但努力使我了解如何构造项目以使用存储过程。
My first thought is that I no longer need models as the stored procedures effectively negate them. 我的第一个想法是,由于存储过程有效地否定了模型,因此不再需要模型。 Am I correct in my thinking? 我的想法正确吗? If I bypass models entirely, how then do I handle things like view models? 如果我完全绕开模型,那我该如何处理像视图模型这样的事情?
For instance I can call a stored procedure like so from my controller: 例如,我可以从控制器中调用存储过程,如下所示:
var vehi_Models = db.spVehicleGetModels(ID_make, false, true, ID_country);
But in cases where I also need other data to send to the view ie: 但是在我还需要其他数据发送到视图的情况下,即:
var vehi_Models = db.spVehicleGetModels(ID_make, false, true, ID_country);
var countries = db.spGetCountries();
Without viewmodels, I am unable to send all the data to the view. 没有viewmodels,我无法将所有数据发送到视图。
Any thoughts or links to any training material I could use would be greatly appreciated. 任何想法或与我可以使用的任何培训材料的链接都将不胜感激。 There isn't a wealth of information out there that I can refer to. 我没有可以参考的大量信息。
Have a look at EntityFramework. 看看EntityFramework。 Although it can directly alter tables you can also edit the function mappings for insert/delete/update to use stored procedures. 尽管它可以直接更改表,但是您也可以编辑功能映射以进行插入/删除/更新以使用存储过程。
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.