none
Entity framework relation RRS feed

  • Question

  • Hi 

    let me know How to get the 5th and above level of relation value by using entity.

    Here is the code.

     Dim vEntidad As MainEntity

        Public Sub New()
            ' Llamada necesaria para el diseñador.
            InitializeComponent()
            ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
            vEntidad = New MainEntity
            Dim vFar As New FarEntity With {.UnreachableProperty = "This property will not be shown.", .id = 153}
            Dim vFather3 As New Entidad12 With {.id = 22, .FarProperty2 = "Property of Entity 12"}
            Dim vFather2 As New Entidad13 With {.id = 333, .FarProperty3 = "Property of Entity 13"}
            Dim vFather As New Entidad14 With {.id = 1}
            vFather.SecondFather = vFather2
            vFather.Father_ID = vFather2.id
            vFather2.ThirdFather = vFather3
            vFather2.Father_ID = vFather3.id
            vFather3.LastFather = vFar
            vFather3.Father_ID = vFar.id
            vEntidad.FirstFather = vFather
            vEntidad.Father_ID = vFather.id
            Dim lData As New List(Of MainEntity)
            lData.Add(vEntidad)        
            Me.DataGridView1.DataSource = lData
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim vResultado As String = vEntidad.FirstFather.SecondFather.ThirdFather.LastFather.UnreachableProperty
            Debug.Print("Property value through code: " & vResultado)
            MsgBox("Property value through code: " & vResultado)
        End Sub

    The Unreachable property returns only empty. but its have a value.

    • Moved by Yang,Chenfei Wednesday, July 31, 2013 2:10 AM Move Threads
    Thursday, July 25, 2013 3:40 AM

Answers

  • Hello Ragamathullah,

    Welcome toMSDN Support Forum.

    Based on my analysis of codes provided by you,I made an sample.

    Following is the code:

    These are the five entity classes:

    Class MainEntity:

    Public Class MainEntity
        Public FirstFather As Entidad14
        Public id As Integer
        Public Father_ID As Integer
    End Class

    Class Entidad14:

    Public Class Entidad14
        Public SecondFather As Entidad13
        Public id As Integer
        Public Father_ID As Integer
    End Class

    Class Entidad13:

    Public Class Entidad13
        Public ThirdFather As Entidad12
        Public id As Integer
        Public Father_ID As Integer
        Public FarProperty3 As String
    End Class

    Class Entidad12:

    Public Class Entidad12
        Public LastFather As FarEntity
        Public id As Integer
        Public Father_ID As Integer
        Public FarProperty2 As String
    End Class

    Class FarEntity:

    Public Class FarEntity
        Public id As Integer
        Public UnreachableProperty As String
    End Class

    And the windows form code copys from yours:

    Public Class Form1
        Dim vEntidad As MainEntity
        Public Sub New()
            ' Llamada necesaria para el diseñador.
            InitializeComponent()
            ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
            vEntidad = New MainEntity
            Dim vFar As New FarEntity With {.UnreachableProperty = "This property will not be shown.", .id = 153}
            Dim vFather3 As New Entidad12 With {.id = 22, .FarProperty2 = "Property of Entity 12"}
            Dim vFather2 As New Entidad13 With {.id = 333, .FarProperty3 = "Property of Entity 13"}
            Dim vFather As New Entidad14 With {.id = 1}
            vFather.SecondFather = vFather2
            vFather.Father_ID = vFather2.id
            vFather2.ThirdFather = vFather3
            vFather2.Father_ID = vFather3.id
            vFather3.LastFather = vFar
            vFather3.Father_ID = vFar.id
            vEntidad.FirstFather = vFather
            vEntidad.Father_ID = vFather.id
            Dim lData As New List(Of MainEntity)
            lData.Add(vEntidad)
            Me.DataGridView1.DataSource = lData
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim vResultado As String = vEntidad.FirstFather.SecondFather.ThirdFather.LastFather.UnreachableProperty
            Debug.Print("Property value through code: " & vResultado)
            MsgBox("Property value through code: " & vResultado)
            TextBox1.Text = vResultado
        End Sub
    End Class

    And while I click the button and it prints “Property value through code:This property will not be shown”.It returns an string value.

    These entity classes are created by myself and they are maybe different than yours. So would you please share your entity class code so that we can help you better.

    Here is my skydrive link:

    http://sdrv.ms/1aW7PeA.

    There is a complete sample. You can download it and run it in your computer.

    If it is un-work in your computer,could you please share your complete app on skydrive.

    The link : https://skydrive.live.com/.

    Or you can send it to my mailbox: support-v-minbao@hotmail.com.

    I will run it on my computer and find the difference between your code and my.

    Thank you for your understanding and support.

    I look forward to hearing from you.

    Best Regards


    Fred Bao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 31, 2013 7:47 AM
    Moderator

All replies

  • Hi,

    Thank you for visiting the MSDN forum. I’m afraid that it is not the correct forum about this issue, since this forum is to discuss Visual Basic.

    I am moving your question to ADO.NET Entity Framework and LINQ to Entities Forums. You can get a better response from that forums.

    ADO.NET Entity Framework and LINQ to Entities Forums

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    Thanks for your understanding.

    Best Regards

    Jimmy


    Jimmy Yang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 31, 2013 2:09 AM
  • Hello Ragamathullah,

    Welcome toMSDN Support Forum.

    Based on my analysis of codes provided by you,I made an sample.

    Following is the code:

    These are the five entity classes:

    Class MainEntity:

    Public Class MainEntity
        Public FirstFather As Entidad14
        Public id As Integer
        Public Father_ID As Integer
    End Class

    Class Entidad14:

    Public Class Entidad14
        Public SecondFather As Entidad13
        Public id As Integer
        Public Father_ID As Integer
    End Class

    Class Entidad13:

    Public Class Entidad13
        Public ThirdFather As Entidad12
        Public id As Integer
        Public Father_ID As Integer
        Public FarProperty3 As String
    End Class

    Class Entidad12:

    Public Class Entidad12
        Public LastFather As FarEntity
        Public id As Integer
        Public Father_ID As Integer
        Public FarProperty2 As String
    End Class

    Class FarEntity:

    Public Class FarEntity
        Public id As Integer
        Public UnreachableProperty As String
    End Class

    And the windows form code copys from yours:

    Public Class Form1
        Dim vEntidad As MainEntity
        Public Sub New()
            ' Llamada necesaria para el diseñador.
            InitializeComponent()
            ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
            vEntidad = New MainEntity
            Dim vFar As New FarEntity With {.UnreachableProperty = "This property will not be shown.", .id = 153}
            Dim vFather3 As New Entidad12 With {.id = 22, .FarProperty2 = "Property of Entity 12"}
            Dim vFather2 As New Entidad13 With {.id = 333, .FarProperty3 = "Property of Entity 13"}
            Dim vFather As New Entidad14 With {.id = 1}
            vFather.SecondFather = vFather2
            vFather.Father_ID = vFather2.id
            vFather2.ThirdFather = vFather3
            vFather2.Father_ID = vFather3.id
            vFather3.LastFather = vFar
            vFather3.Father_ID = vFar.id
            vEntidad.FirstFather = vFather
            vEntidad.Father_ID = vFather.id
            Dim lData As New List(Of MainEntity)
            lData.Add(vEntidad)
            Me.DataGridView1.DataSource = lData
        End Sub
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim vResultado As String = vEntidad.FirstFather.SecondFather.ThirdFather.LastFather.UnreachableProperty
            Debug.Print("Property value through code: " & vResultado)
            MsgBox("Property value through code: " & vResultado)
            TextBox1.Text = vResultado
        End Sub
    End Class

    And while I click the button and it prints “Property value through code:This property will not be shown”.It returns an string value.

    These entity classes are created by myself and they are maybe different than yours. So would you please share your entity class code so that we can help you better.

    Here is my skydrive link:

    http://sdrv.ms/1aW7PeA.

    There is a complete sample. You can download it and run it in your computer.

    If it is un-work in your computer,could you please share your complete app on skydrive.

    The link : https://skydrive.live.com/.

    Or you can send it to my mailbox: support-v-minbao@hotmail.com.

    I will run it on my computer and find the difference between your code and my.

    Thank you for your understanding and support.

    I look forward to hearing from you.

    Best Regards


    Fred Bao
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 31, 2013 7:47 AM
    Moderator