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

Can someone explain Managed Collections?

7 Answers 89 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 22 Mar 2010, 02:32 AM
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

7 Answers, 1 is accepted

Sort by
0
Sergej Mertens
Top achievements
Rank 1
answered on 22 Mar 2010, 11:07 AM
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
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 22 Mar 2010, 11:21 AM
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?
0
Accepted
Sergej Mertens
Top achievements
Rank 1
answered on 22 Mar 2010, 11:45 AM
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
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 22 Mar 2010, 12:28 PM
I shall give it a try, thanks!
0
Zoran
Telerik team
answered on 22 Mar 2010, 01:36 PM
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.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 22 Mar 2010, 01:39 PM
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?
0
Zoran
Telerik team
answered on 22 Mar 2010, 04:31 PM
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.
Tags
Getting Started
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Sergej Mertens
Top achievements
Rank 1
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Zoran
Telerik team
Share this question
or