This project is read-only.

Contentparts with 1-n relations

Topics: General, Writing modules
Apr 15, 2011 at 8:38 AM


I've read the documentation Creating 1-N and N-N Relations (

I would like to create a module similiar to the one described in 1-n relationship.

The difference is I want to enter the states within the portal itself. I guess to accomplish this I have to implement the StateRecord as a contentpart as well. But I could not manage how to declare both contentparts and related contentpartrecords.

In the documentation the relationship is supplied between StateRecord and AddressPartRecord as follows:

public virtual StateRecord StateRecord { get; set; }

How should it be implemented if staterecord is a contentpartrecord?

Thank you

Creating 1-N and N-N Relations

Apr 15, 2011 at 8:40 AM

You just need to read a little further, into the n-n section.

Apr 15, 2011 at 9:23 AM

Doesn't n-nsection also deals with one ContenPart (namely RewardsPart) ?

My issue is handling two (or more) ContentParts.

Apr 15, 2011 at 10:02 AM

"How should it be implemented if staterecord is a contentpartrecord?"

It shouldn't matter. A contentpartrecord is just a normal database record that happens to share a primary key with the contentitems table.

That article has a section even further down, after the n-n part, with a heading "Building a Relation Between Content Items"; does that help?

Apr 15, 2011 at 11:18 AM

It is stated on the documentation:

The interesting column here is StateRecord_Id. As you can see, its type is the same as the type of the Id column of the StateRecord class, because the system will be able to recognize this as a foreign key and to map that integer value to a StateRecord property by just following the relation. It is important here that the name of the column that will represent the relation is the name of the column on the "1" end of the relation, followed by an underscore and the name of the column of the "n" end of the relation.

But if I implement StateRecord as a ContentPartRecord, Id column will not be implemented explicitly and will be included by .ContentPartRecord().

Should I implement a StateRecord_Id in the same way?

Apr 15, 2011 at 11:51 AM

It's still the same thing. ContentPartRecord still has an Id field for which StateRecord_Id will be implicitly created to join to.

Apr 15, 2011 at 12:27 PM

Thank you very much. I guess the notation is important for the system. (i.e. I cannot use StRec_Id for that field?) Am I correct?

Apr 15, 2011 at 1:25 PM

As long as it matches the joined property.

So if you had:

public virtual ContentItemRecord StRec { get; set; }

Then StRec_Id is the name of the foreign index by convention. It doesn't depend on the type of the joined record; this way, you can have multiple joins to the same table.

Dec 2, 2012 at 11:19 PM


For last part show how get one value 1-n relationship from n-side.

But how i can get n values from 1-side?

Dec 3, 2012 at 12:20 AM

Not sure I understand your question. This seems to be covered by the doc topic, but I'm really not sure I understand what you're asking. Can you please restate this using the examples from the topic?