Home All Groups Group Topic Archive Search About
Author
2 Jul 2009 3:03 PM
Evan Nielsen
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?

Author
2 Jul 2009 3:30 PM
Lloyd Sheen
Show quote Hide quote
"Evan Nielsen" <EvanNiel***@discussions.microsoft.com> wrote in message
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?

Could you provide SQL table definition and LINQ code to get the data.
Without that it is dificult to say what may be wrong.

LS