我有以下代碼。最後的foreach是不必要的,因爲只會返回一行。如何使用Linq to Entities從此集合中獲取第一個值?
那麼如何從userGroups中獲取一個值而不必循環?
感謝 凱文
using (kdEntities db = new kdEntities())
{
Label lbl = sender as Label;
IQueryable<UserGroup> userGroups = from UserGroup in db.UserGroups where UserGroup.UgpID == 1 select UserGroup;
foreach (var group in userGroups)
{
lbl.Text = group.UgpDescription;
}
}
簡單,輕鬆的檸檬榨汁+1 –