The operator '=' is not defined for types Integer and IQueryable (Of Integer) '

It gives me a headache. I have this link request that captures id

Dim mclassID = From x In db.SchoolClasses Where x.VisitDateID = _visitdateID Select x.ClassID

And then later I have this linq request

ViewData("Staff") = From t In db.Staffs Where t.ClassID = mclassID Select t

Any help would be greatly appreciated. I tried a lot of things, but to no avail. I tried casting, transforming, this is an operand, etc.

+3
source share
6 answers

, myClassID IQueryable. (List - ), . , List(Of Integer), First() , . - :

Dim myClassIDList As List(Of Integer) = New List(Of Integer)( _
    From x In db.SchoolClasses Where x.VisitDateID = _visitdateID Select x.ClassID)

Dim myClassID as Integer = myClassIDList.First()
+1

, ? :.

ViewData("Staff") = (From t In db.Staffs Where t.ClassID = mclassID Select t)
0

Dim mclassID = From x In db.SchoolClasses Where x.VisitDateID = _visitdateID Select x.ClassID

, , IEnumerable, .

-

ViewData("Staff") = From t In db.Staffs Where mclassID.Contains(t.ClassID) Select t

mclassID IEnumerable int.

0

Select, . (.. ), Single SingleOrDefault ( , ), .

Dim mclassID = (From x In db.SchoolClasses _
               Where x.VisitDateID = _visitdateID _
               Select x.ClassID).SingleOrDefault()
0

, : -

VS2010 // / /
MSBuild Project, ""

I had a similar error that did not appear in the error list, but with this parameter setting I saw: - error BC30452: The operator '=' is not defined for the types "System.Nullable (Of Integer)" and "Integer". from this statement: - If tqGDBChart.UserIsGroupAdmin (Userid, Groupid) = 0 Then "The user is not a group administrator for this group

It is easy to fix it with an intermediate variable.

Dim GroupAdminCount As Integer = tqGDBChart.UserIsGroupAdmin(Userid, Groupid)
If GroupAdminCount = 0 Then   'User is not a group admin for this group
0
source

You tried:

ViewData("Staff") = From t In db.Staffs Where t.ClassID.equals(mclassID)  Select t
-1
source

Source: https://habr.com/ru/post/1757844/


All Articles