Linq查询以从ASP.NET MVC 2中的数据库获取结果 [英] Linq query to get results from DB in ASP.NET MVC 2
本文介绍了Linq查询以从ASP.NET MVC 2中的数据库获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Ling to Entities查询.
How do I query using Ling to Entities.
我想找回特定用户的总行数.
I want to get back the total number of rows for a specific user.
我创建了一个具有ID(PK),用户名和电话号码的表.
I created a table with an ID(PK), Username, and PhoneNumber.
在我的控制器中,我可以执行此操作并查看我的实体:
In my controller, I am able to do this and see my entities:
public ActionResult UserInfo()
{
using (UserInfoEntities db = new UserInfoEntities())
{
}
return View();
}
如何查询以返回总行数并将其声明为变量(总计),以便可以执行以下操作:
How do I query to return the total number of rows and declare it to a variable (totalrows) so that I can do thge following:
ViewData["TotalRows"] = totalrows
如果有更好的方法,我愿意接受建议...
If there is a better way I am open to suggestions...
谢谢!
推荐答案
可能类似于:
int count = db.SomeTable.Where(r => r.Username.Equals("username")).Count();
这篇关于Linq查询以从ASP.NET MVC 2中的数据库获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文