Value of type 'System.Linq.IQueryable(Of Integer)' cannot be converted to Integer
I am new to EF Linq and I have been struggling with this query for a few days. From reading this forum, I have managed to get this far:
Dim noPic = (From f In myEntities.FriendLists
Where (f.UserID = Profile.ID)
Select f.FriendID).Except(From g In myEntities.GuestLists
Where g.EventID = _id
Select g.FriendID)
Dim myNoPic As Integer = noPic
Dim show = From s In myEntities.UserProfiles
Where s.UserID = myNoPic
Select s.UserID, s.FirstName, s.LastName, s.ImUrl
Repeater2.DataSource = show
Repeater2.DataBind()
I am trying to get everybody from the FriendList who is not already on the GuestList to display in a Repeater control. After reading the forum I was able to append .First() to noPic at the myNoPic declaration and finally get a result but that only gave me the first element. Does a开发者_Go百科nybody have any advice on how to accomplish this?
noPic
is a query. It's not an integer - it's a sequence of integers. So you can't convert it to a single integer, and it sounds like you don't want it to.
My guess is that you want:
Dim show = From s In myEntities.UserProfiles
Where noPic.Contains(s.UserID)
Select s.UserID, s.FirstName, s.LastName, s.ImUrl
Alternatively, write the whole thing as a join to start with. (I'm not au fait with VB LINQ syntax, otherwise I'd do that for you.)
The problem boils down to these lines:
Dim myNoPic As Integer = noPic
and
Where s.UserID = myNoPic
What I think you are trying to accomplish is something like this:
Dim noPic = (From f In myEntities.FriendLists
Where (f.UserID = Profile.ID)
Select f.FriendID).Except(From g In myEntities.GuestLists
Where g.EventID = _id
Select g.FriendID)
Dim myNoPic As Integer = noPic
Dim show = From s In myEntities.UserProfiles
Where noPic.Contains(s.UserID)
Select s.UserID, s.FirstName, s.LastName, s.ImUrl
Contains
is what we wanted. It changes your second query to "Get me all UserProfiles where their ID is in noPic".
精彩评论