我可以在ASP.net MVC中使用纯SQL吗? [英] Can I use pure SQL in ASP.net MVC?

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

问题描述

hello的家伙,我需要使用纯SQL查询我的数据库项目
在同一时间我想使用ASP.net MVC所以我可以学习一个新的技术!
我可以使用SQL与ASP.net MVC WITHOUT使用LINQ to SQL?
我仍​​然在学习,所以我很抱歉,如果这么愚蠢的使用OLD SCHOOL
的东西,但我的教练坚持他想看到一个PURE SQL查询

解决方案

是的。你可以使用任何你想要的模型层。注意,您可以使用LINQ To SQL的原始SQL查询。

  Northwnd db = new Northwnd(@c:\\\
orthwnd.mdf);
IEnumerable< Customer> results = db.ExecuteQuery< Customer>
(@SELECT c1.custid as CustomerID,c2.custName as ContactName
FROM customer1 as c1,customer2 as c2
WHERE c1.custid = c2.custid
);

或者你的教师想要直接ADO.NET,这也很好。
这里有一个示例。 / p>

hello guys i need to use pure SQL queries for my database project at the same time i wanna use ASP.net MVC so i can learn a new technology !!! can i use SQL with ASP.net MVC WITHOUT using " LINQ to SQL " ?! i'm still learning so i'm sorry if it so stupid using things the OLD SCHOOL but my instructor insists that he want to see a PURE SQL Queries

解决方案

Yes. You can use whatever you want for your model layer. Note, you can use raw SQL queries with LINQ To SQL as well.

Northwnd db = new Northwnd(@"c:\northwnd.mdf");
IEnumerable<Customer> results = db.ExecuteQuery<Customer>
(@"SELECT c1.custid as CustomerID, c2.custName as ContactName
    FROM customer1 as c1, customer2 as c2
    WHERE c1.custid = c2.custid"
);

Or perhaps your instructor wants straight up ADO.NET, which works fine too. There is an example here.

这篇关于我可以在ASP.net MVC中使用纯SQL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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