简体   繁体   English

C#MVC使用SQL Server存储过程构建项目

[英]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.

相关问题 C#Winforms-如何将参数传递给SQL Server存储过程 - C# Winforms - How to Pass Parameters to SQL Server Stored Procedures C# 和 SQL 服务器:更新存储过程有问题 - C# and SQL Server: updating trouble with stored procedures C#访问SQL Server数据库存储过程和视图 - C# access to SQL Server database stored procedures and views C#中的TransactionScope是否可以触发SQL Server中存储过程中的回滚? - Can TransactionScope in C# trigger rollbacks in stored procedures in SQL server? 使用相同的参数在C#中执行多个SQL Server存储过程 - Executing multiple SQL Server stored procedures in C# with the same parameters 用C#编写Server存储过程 - Writing Server stored procedures in c# 是否可以在C#/ SQL Server中使用表变量作为存储过程的参数? - Is it possible to use in C#/SQL Server a table variable as a parameter for stored procedures? C#和SQL Server存储过程-无法获取输出参数值,返回值有效 - C# & SQL Server stored procedures - can't get output parameter value, return value works 使用C#将存储过程从解决方案文件夹添加到SQL Server数据库 - Using C# to add stored procedures from solution folder to SQL Server database 在MVC2中为存储过程制作灵活的C#代码 - Making flexible C# code in MVC2 for Stored Procedures
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM