This is a migrated thread and some comments may be shown as answers.

[Solved] Access Property in 1:M Forward Mapping

3 Answers 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
shawn reagan
Top achievements
Rank 1
shawn reagan asked on 18 Nov 2010, 02:53 AM
Hello.
I'm going through the OpenAccess Made Easy document and samples and have a question.

I've ORM enabled my project and created aCustomer and Order class as defined in section 2.2 and all is working well.  I may be overlooking something, but what I need to do is to be able to fetch the Order object and then access the Customer.CustomerName associated to the Order.

Any guidance appreciated.

Thank you.

3 Answers, 1 is accepted

Sort by
0
shawn reagan
Top achievements
Rank 1
answered on 18 Nov 2010, 02:54 AM
Imports Telerik.OpenAccess
 
Module Module1
 
    Sub Main()
 
        Dim scope As IObjectScope = ObjectScopeProvider1.ObjectScope
 
        scope.Transaction.Begin()
 
        Dim _cust As New Customer
        _cust.CustomerName = "Bob"
        _cust.CustomerNumber = 123
 
        Dim _ord As New Order
        _ord.OrderNumber = 1
        _cust.Orders.Add(_ord)
 
        scope.Add(_cust)
        scope.Transaction.Commit()
 
    End Sub
 
End Module
 
<Telerik.OpenAccess.Persistent()> _
Public Class Customer
 
    Private _customerNumber As Integer
    Private _customerName As String
    Private _orders As IList(Of Order)
 
    Public Sub New()
        Me._orders = New List(Of Order)
    End Sub
 
    Public Property CustomerNumber As Integer
        Get
            Return _customerNumber
        End Get
        Set(ByVal value As Integer)
            _customerNumber = value
        End Set
    End Property
 
    Public Property CustomerName As String
        Get
            Return _customerName
        End Get
        Set(ByVal value As String)
            _customerName = value
        End Set
    End Property
 
    Public Property Orders() As IList(Of Order)
        Get
            Return _orders
        End Get
        Set(ByVal value As IList(Of Order))
            _orders = value
        End Set
    End Property
 
End Class
 
<Telerik.OpenAccess.Persistent()> _
Public Class Order
 
    Private _orderNumber As Integer
 
    <Telerik.OpenAccess.FieldAlias("_orderNumber")> _
    Public Property OrderNumber As Integer
        Get
            Return _orderNumber
        End Get
        Set(ByVal value As Integer)
            _orderNumber = value
        End Set
    End Property
 
   
End Class
0
Accepted
Damyan Bogoev
Telerik team
answered on 19 Nov 2010, 06:38 PM
Hi shawn reagan,

You should do the following steps in order to achieve this goal:
-   Add a Customer field and property within the Orders class:

Private _customer As Customer
 
<Telerik.OpenAccess.FieldAlias("_customer")> _
Public Property CustomerInstance As Customer
    Get
        Return _customer
    End Get
    Set(ByVal value As Customer)
        _customer = value
    End Set
End Property

-   Add the following setting within the app.config file:

<field name="_orders">
 <collection
   <extension key="inverse" value="_customer" />
   <extension key="managed" value="false" />
 </collection>
</field>

Additional information regarding one-to-many mapping can be found here.
Hope that helps.

Best wishes,
Damyan Bogoev
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
0
shawn reagan
Top achievements
Rank 1
answered on 20 Nov 2010, 01:57 AM
I got it using the information you gave me and the following link.
http://www.telerik.com/community/forums/orm/general-discussions/can-t-create-managed-one-to-many-collection.aspx

Thank you so much for the help.
Tags
General Discussions
Asked by
shawn reagan
Top achievements
Rank 1
Answers by
shawn reagan
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or