Can someone explain Managed Collections?

8 posts, 1 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 21 Mar 2010 Link to this post

    I've been using Reverse mapping only right now...

    So I have a request object, which has a collection to a list of Dates which correspond to that request.

    How do I rejigger my project so I can just
    Request request = new Request();
    request.Dates.Add(new RequestedDate(...));

    scope.Add(request);
    scope.Commit();

    Right now I just make all the objects and IDs individually and add them in one at a time to their respective tables.  I was thinking it'd be more readable adding to the parent object.

    Thanks,
    Steve
  2. Sergej Mertens
    Sergej Mertens avatar
    34 posts
    Member since:
    May 2009

    Posted 22 Mar 2010 Link to this post

    Hi Steve,

    your request is a very common task. And am I right, that you now want to forward-map the first time? Then here we go:
    You have two objects "Request" and "RequestedDate". I assume thet this is a 1:n-relationship. Just take a look here:
    http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-forward-mapping-wizard.html

    A short note:
    I always use backlinking to the master in details ("Request" in RequestedDate). So make sure to uncheck "JOIN table" in screenshot under
    "The last field-specific view of the forward mapping wizard is when a collection field is selected. For an example we have the "details" collection of the Order class which contains all the OrderDetail objects referring to a specific "Order" instance in the object graph."

    Greetings,
    Daniel
  3. DevCraft banner
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 22 Mar 2010 Link to this post

    Does this mean I now have to forward map my schema?...or I can still modify in SQL and just use this to link the collections?
  5. Answer
    Sergej Mertens
    Sergej Mertens avatar
    34 posts
    Member since:
    May 2009

    Posted 22 Mar 2010 Link to this post

    Hi Steve,

    you can use reverse- and forward-mapping simultaneously. You can first use reverse-mapping and set the needed options. Add a reference field (if not done automatically):
    1. Open reverse-mapping-wizard, select 2nd Tab "Advanced View".
    2. Select the RequestedDate table and click on "Create Ref" on the right.
    3. Select "Request" on Type combo and enter the field name for back-linking (e.g. _request).
    4. Check "Field to Column Mapping".

    Then you can use forward-mapping or adding the needed parts by hand:
    1. Add a new property "Dates" with a member variable "_dates" to the Request-class
    2. open app.config, navigate to the class section for "Request"
    3. add a new entry
    <field name="_dates"
       <collection> 
          <extension key="inverse" value="_request" /> 
          <extension key="managed" value="true" /> 
       </collection> 
    </field> 

    Note: the inverse field value must be the field from your RequestDates-class.

    Greetings,
    Daniel
  6. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 22 Mar 2010 Link to this post

    I shall give it a try, thanks!
  7. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 22 Mar 2010 Link to this post

    Hi Steve,

    Actually it is not required for you to forward map your schema. In the Reverse Mapping Wizard, if you select the reference property in the 'Advanced View', there is a checkbox "Create one-to-many list". If you check that checkbox it will create the list on the parent class. So for example, under the RequestDate node you should have a Request field sub-node which you should select and then check the mentioned checkbox.
    I would also like to point you out that if you use the new designer to generate the code, the collections will be generated out of the box, no additional settings required. This is one of the enhancements we delivered for better user experience while mapping your classes in design-time.

    Kind regards,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 22 Mar 2010 Link to this post

    I do have the collections generated from the advanced tab already....so I can just use them as a normal collection with no forward mapping at all?...cascading delete works and all that other goodness?
  9. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 22 Mar 2010 Link to this post

    Hi Steve,

    Yes, you can use them without no forward mapping at all. For cascading delete though, you will have to place the 'Depend' attribute over the collections that you would like to be deleted that way. With the new designer this is also not necessary as the designer has one checkbox that controls the cascading deletion in UI.

    Kind regards,
    Zoran
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner