[英]MVC 4 SQL Server, how can i get the first record in a table?
How can I get the first record in a table independent of the rows primary key? 如何在独立于行主键的表中获取第一条记录?
I'm using MVC 4, with EF Code First and a database context, or will I have to use LINQ for this? 我正在使用MVC 4,EF Code First和数据库上下文,还是我必须使用LINQ?
I think I can use db.ToList()
to get the list and then loop through the specific elements, but wouldn't that "download" the whole table? 我想我可以使用
db.ToList()
来获取列表然后遍历特定元素,但是不会“下载”整个表吗?
Cause if it does Isn't it bad practice and inefficient? 如果它确实是不是不好的做法和效率低下?
EDIT: Meant to say "first record", sorry for any confusion :) 编辑:意味着说“第一条记录”,对不起任何混乱:)
Have you tried: 你有没有尝试过:
db.List.First();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.