日期:2014-05-17  浏览次数:20417 次

MVC3.0+SQL语句
求:MVC3.0+SQL语句源码,网上找到的都是用的linq的找不到纯SQL,谢谢了,测试通过就给分

------解决方案--------------------
不是一样的么,
比如你看到
ViewResult Index(int catid)
{
var model = dbContext.Articles.Where(x => x.Cat == catid);
return new View(model);
}
改写成ADO.NET的就是
ViewResult Index(int catid)
{
List<Article> model = new List<Article>();
SqlConnection conn = new SqlConnection(connstring);
SqlCommand cmd = new SqlCommand("select * from Articles where id ='" + catid.ToString + "'", conn);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Article a = new Article();
a.id = reader.GetValue(0);
a.title = reader.GetValue(1);
...
model.Add(a);
}
return new View(model);
}
只是大概写写,很容易懂的。
------解决方案--------------------
我觉得在MVC中使用T-SQL语句,也违背了面向对象,更违背了MVC的设计理念!模型-试图-控制器