locked
OData Refering EntitySet in Another EntitySet RRS feed

  • Question

  • User-240166216 posted

    I want to use one entity in another entity in OData v4 but it gives me below error , How can this be done. If i create a duplicate class of CustomerEntity and use that than it works fine. Could any one help me?

    OData exception The complex type 'AccountEntity' refers to the entity type 'CustomerEntity' through the property 'AccountCustomer'

    Dim builder As New ODataConventionModelBuilder()
    
        builder.EntitySet(Of CustomerEntity)("Customers")
    
        builder.EntitySet(Of AccountEntity)("Accounts")
    
        Dim edmModel = builder.GetEdmModel()
    
    
    
        Public Class AccountEntity
    
            Private _intAccountId As Integer
            Private _AccountCustomers As CustomerEntity
    
            <Key> _
            Public Property AccountId() As Integer
                Get
                    Return _intAccountId
                End Get
                Set(ByVal Value As Integer)
                    _intAccountId = Value
                End Set
            End Property
    
            Public Property AccountCustomers() As CustomerEntity
                Get
                    Return _AccountCustomers
                End Get
                Set(ByVal Value As CustomerEntity)
                    _AccountCustomers = Value
                End Set
            End Property
    
    
    
        End Class



    Friday, April 24, 2015 11:12 AM

Answers

  • User1644755831 posted

    Hello AjaySB,

    You probably need to use it as Navigation property try to change 'CustomerEntity' as virtual Icollection type. Then in the CustomerEntity you need to add a foreign key which tells which accountcustomer it refers to.

    You can follow this example which displays Entity Relations in OData v4 Using ASP.NET Web API 2.2 works.

    Hope this helps.

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 27, 2015 1:28 AM