|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
LINQ and Reflectionget to a string property at the end of the tree. I am storing a string in the database that is formatted as such: <property name>.<property name>.<property name>.<property name> The string can be as many properties long as needed. I am using reflection to loop through each property and return the object related to that property, then the next returning the next property on the list. Code Follows: For i As Integer = 0 To strDestination.Length - 1 pi = cobraType.GetProperty(strDestination(i)) cobraObj = pi.GetValue(cobraObj, BindingFlags.GetProperty, Nothing, Nothing, Nothing) cobraType = cobraType.GetProperty(strDestination(i)).PropertyType Next The initial value of cobraObj is the instance of the upper most object in the tree that I am traversing. The issue with this is that the initial object (cobraObj) is being populated by LINQ and for some reason when I end up calling properties that are nested down two or three levels they return nothing even though those objects exist if i were to just make a call to them like Me.propertyname.propertyname.propertyname. I was thinking that this may be caused by the fact that LINQ does deferred execution and the properties are not being populated. What should I do to fix this issue?
Show quote
Hide quote
"Evan Nielsen" <EvanNiel***@discussions.microsoft.com> wrote in message Could you provide SQL table definition and LINQ code to get the data. news:55CCFA82-8E24-46F9-8334-1709816BC6F1@microsoft.com... >I have a piece code where I am traversing an objects properties to >eventually > get to a string property at the end of the tree. > > I am storing a string in the database that is formatted as such: > <property name>.<property name>.<property name>.<property name> > The string can be as many properties long as needed. > > I am using reflection to loop through each property and return the object > related to that property, then the next returning the next property on the > list. Code Follows: > > For i As Integer = 0 To strDestination.Length - 1 > pi = cobraType.GetProperty(strDestination(i)) > cobraObj = pi.GetValue(cobraObj, > BindingFlags.GetProperty, Nothing, Nothing, Nothing) > cobraType = > cobraType.GetProperty(strDestination(i)).PropertyType > Next > > The initial value of cobraObj is the instance of the upper most object in > the tree that I am traversing. The issue with this is that the initial > object (cobraObj) is being populated by LINQ and for some reason when I > end > up calling properties that are nested down two or three levels they return > nothing even though those objects exist if i were to just make a call to > them > like Me.propertyname.propertyname.propertyname. > > I was thinking that this may be caused by the fact that LINQ does deferred > execution and the properties are not being populated. > > What should I do to fix this issue? Without that it is dificult to say what may be wrong. LS
vb.net and Ms SQL Connection ?
Using "Me" Using WPF with a "normal" windows app Unable to connect to the remote server How to reference class properties using MyClass("PropertyName") VB Net/Com Interoperability/Late Binding Serializing Custom Generic Collection (Of InterfaceType) DataGridView Event Web server is not running ASP.NET version 1.1. Add Line Break to mail body |
|||||||||||||||||||||||