Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to entities. GetPropety(name).GetValue not recognised by linq
    primarykey
    data
    text
    <p>I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:</p> <pre><code>Dim fields As List(Of CheckableFields) = New List(Of CheckableFields) Using context As ITIPEntities = New ITIPEntities() Try Dim propertyInfoList As List(Of PropertyInfo) = GetType(PC).GetProperties().ToList() For Each pI In propertyInfoList If (pI.PropertyType &lt;&gt; GetType(EntityState) _ And pI.PropertyType &lt;&gt; GetType(EntityKey) _ And pI.PropertyType &lt;&gt; GetType(EntityCollection(Of DiskDrive)) _ And pI.PropertyType &lt;&gt; GetType(EntityCollection(Of Memory)) _ And pI.PropertyType &lt;&gt; GetType(EntityCollection(Of Monitor)) _ And pI.PropertyType &lt;&gt; GetType(EntityCollection(Of Network)) _ And pI.PropertyType &lt;&gt; GetType(EntityCollection(Of Processor))) Then fields.Add(New CheckableFields(pI.Name)) End If Next Catch ex As Exception End Try End Using </code></pre> <p>Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:</p> <pre><code>For Each checkedField In _requiredFields If checkedField.IsChecked Then If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then Dim fieldData As String = checkedField.FieldData Dim name As String = checkedField.Name lquery = From comp In lquery Where CType(comp.GetType.GetProperty(name).GetValue(comp, Nothing), String).ToUpper.Contains(fieldData.ToUpper) Select comp End If End If Next </code></pre> <p>Which throws the exception that linq doesn't recognize the GetValue method.</p> <p>How can I get the property values dynamically?</p> <p>Edit:</p> <p>I couldn't find a way to do this with Linq to Entities, but I did find a way without Linq that works for me:</p> <pre><code>For Each field In _requiredFields If field.IsChecked Then reportGenerator.AllFields.Add(field.Name) If field.FieldData IsNot Nothing Then For i As Integer = pcs.Count - 1 To 0 Step -1 Dim compPropertyValue As String = CType(pcs(i).GetType().GetProperty(field.Name).GetValue(pcs(i), Nothing), String).ToUpper() If Not compPropertyValue.Contains(field.FieldData.ToUpper()) Then pcs.RemoveAt(i) End If Next i End If End If Next </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload