|
| LINQ basic learning question |
 |
Mon, 31 Mar 2008 17:15:28 +000 |
Hello. Why does this work: Dim db AsNew SafeTekUSADataClassesDataContextDim
FName = (From p In db.Company_Memberships Where p.EmpUserID = user_currentUserID
Select p.FirstName).First.ToString()
Label10.Text = FName
_________
But this one doesn't? It only returns one record so the "First, is
actually selecting the only possible record. If someone can help me undestand
this I would appreciate it!Dim db AsNew SafeTekUSADataClassesDataContext
Dim FName = From p In db.Company_Memberships Where p.EmpUserID =
user_currentUserID Select p.FirstName.ToString()
Label10.Text = FName
|
| Post Reply
|
| Re: LINQ basic learning question |
 |
Mon, 31 Mar 2008 20:26:56 +000 |
Your second query is returning a result set of all those records matching your
WHERE clause. Even though this may return a single record, it is returned as an
IEnumerable result set which contains a single element. Therefore, this result
set CAN NOT be applied to the Text property of your Label.
Your first query guarantees that a single object will be returned and the
FirstName of that object CAN be applied to the Text property of your Label.
|
| Post Reply
|
| Re: LINQ basic learning question |
 |
Mon, 31 Mar 2008 20:45:20 +000 |
Great, thanks much!
|
| Post Reply
|
|
|
|
|
|
|
|
|
|