FieldValue LINQ query returns the same result

Thread is closed for posting
2 posts, 0 answers
  1. Mark
    Mark avatar
    1 posts
    Member since:
    Jan 2011

    Posted 24 Mar 2011 Link to this post


    I am trying to use a LINQ query to get the value of a particular field from a database view (VwUserInformation). I pass in the name of the field that I want (fieldName) into the function and use it in the query as the parameter for FieldValue. See the code below.

    On the first call to the function I set fieldName to "UserID", I get the data that is in the UserID field. On the second call, fieldName equals "UserFullName", but I still get the data from the UserID field. Even if I put in a bad value for fieldName (a field name that doesn't exist in the table), I still get the UserID and no error. Is there a way to fix this so I get the value of the field I specify and not just the value of the first field that was sent to this function?


        Public Function GetUserData(ByVal fieldName As StringByVal userID As StringOptional ByVal defaultValue As String = ""As String Implements IMedVizerDbCom.GetUserData
            Dim dbData As String
            Dim tempUserData As Object
            Dim id As New Guid(userID)
            dbData = Nothing
            Dim x As IQueryable(Of Object) = From users In dbContext.VwUserInformation
                                             Where (users.UserID = id)
                                             Select users.FieldValue(Of Object)(fieldName)
            tempUserData = x.First
            If (Object.ReferenceEquals(tempUserData.GetType(), New Boolean().GetType)) Then
                If (DirectCast(tempUserData, Boolean) = TrueThen
                    dbData = "1"
                    dbData = "0"
                End If
                dbData = tempUserData.ToString
            End If
            If (dbData Is NothingThen
                dbData = defaultValue
            End If
            Return dbData
        End Function
  2. Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 29 Mar 2011 Link to this post

    Hello Mark,

    I am afraid that there is an issue with the FieldValue method when it is used in a function. We will investigate the cause for this issue and fix it.
    Actually there is a workaround that you could use in order to avoid the error. I prepared a sample application that shows how to achieve that goal. It uses a dynamic LINQ in order to select the correct data.
    I am sorry for the inconvenience caused.
    You could find your Telerik points updated.

    All the best,
    Damyan Bogoev
    the Telerik team
Back to Top