Vb.net Linq对实体的访问。GetProperty(名称)。linq无法识别GetValue
我的xaml表单上有一个listbox,我将它绑定到一个MyType属性的ListOf。我这样填写了这个列表:Vb.net Linq对实体的访问。GetProperty(名称)。linq无法识别GetValue,vb.net,linq-to-entities,Vb.net,Linq To Entities,我的xaml表单上有一个listbox,我将它绑定到一个MyType属性的ListOf。我这样填写了这个列表: Dim fields As List(Of CheckableFields) = New List(Of CheckableFields) Using context As ITIPEntities = New ITIPEntities() Try Dim propertyInfoList As List(Of PropertyIn
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 <> GetType(EntityState) _
And pI.PropertyType <> GetType(EntityKey) _
And pI.PropertyType <> GetType(EntityCollection(Of DiskDrive)) _
And pI.PropertyType <> GetType(EntityCollection(Of Memory)) _
And pI.PropertyType <> GetType(EntityCollection(Of Monitor)) _
And pI.PropertyType <> GetType(EntityCollection(Of Network)) _
And pI.PropertyType <> GetType(EntityCollection(Of Processor))) Then
fields.Add(New CheckableFields(pI.Name))
End If
Next
Catch ex As Exception
End Try
End Using
这引发了一个异常,linq无法识别GetValue方法
如何动态获取属性值
编辑:
我找不到一种使用Linq到实体的方法,但我确实找到了一种不使用Linq的方法:
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
LINQ to实体中不支持此构造。这是一个设计上的限制。 尝试改用实体SQL,如下例所示:
选择值comp From COMPs AS comp WHERE comp.&name&.ToUpper.Contains&fieldData&.ToUpper您是对的,我在Linq中找不到这样做的方法,所以我在没有Linq的情况下完成了
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