sql - 我可以在 ASP.net MVC 中使用纯 SQL 吗?

标签 sql asp.net-mvc database linq-to-sql

大家好,我需要为我的数据库项目使用纯 SQL 查询 同时我想使用 ASP.net MVC 这样我就可以学习新技术!!! 我可以在不使用“LINQ to SQL”的情况下将 SQL 与 ASP.net MVC 一起使用吗?! 我还在学习,所以我很抱歉,如果使用 OLD SCHOOL 的东西太愚蠢了 但是我的老师坚持要看纯 SQL 查询

最佳答案

是的。您可以为模型层使用任何您想要的东西。请注意,您也可以将原始 SQL 查询与 LINQ To SQL 一起使用。

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"
);

或者您的讲师可能想要直接使用 ADO.NET,它也能正常工作。 有一个 example here .

关于sql - 我可以在 ASP.net MVC 中使用纯 SQL 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4594233/

相关文章:

mysql添加外键约束错误

javascript - xmlhttprequest 无法仅使用 post 方法加载 'access-control-allow-origin' (Angularjs)

php - 有没有办法只能获取两个日期之间的数据集?

php - mysql中如何根据where进行计数? PHP

php - 远程 mysql 不会通过 php/mysqli 连接

php - 如何让查询按降序排列的一组值添加排名

sql - SET NOEXEC ON 如何工作?

mysql - 如何重写这个嵌套查询?

html - ASP MVC 无法覆盖 Bootstrap css

asp.net-mvc - 获取 ActionLink 中下拉列表的选定值 (MVC 5)