<commit_before>
It is very common for contents to consist in part of lists or choices in lists. For example, an address can have a state or region property where the value is one in a predefined list of choices. That is a 1-n relationship. A n-n relationship could be for example a list of commercial rewards that a customer can benefit from. Orchard does of course provide support for those scenarios. This topic is going to walk you through the creation of such contents.


# Building a _1-N_ Relationship

The model that we're going to build here consists of an Address part that can be attached for example to a Customer content type. The address part has a street address, a zip code, a city name and a state. The state is what we are going to model as a 1-n relationship to a table of states.

> Note: this is clearly over-normalized, as a state in an address would usually be sufficiently well represented by a simple two-letter state code. The UI can then take care of representing the choice of that code as a constrained choice in a list of states. We are not claiming what we are building here is the correct way to represent a state in an address, but that the process exposed here is representative of what you'd follow to build a real-world 1-n association in Orchard.

## Modeling the Address Part

Here is the code for the `Address` part:

    
    using Orchard.ContentManagement;
    
    namespace RelationSample.Models {
        public class AddressPart : ContentPart<AddressPartRecord> {
            public string Address {
                get { return Retrieve(r => r.Address); }
                set { Store(r => r.Address, value); }
            }
            
            public string City {
                get { return Retrieve(r => r.City); }
                set { Store(r => r.City, value); }
            }
            
            public StateRecord State {
                get { return Retrieve(r => r.State); }
                set { Store(r => r.State, value); }
            }
            <commit_msg>fixed a bug I introduced<commit_after>
It is very common for contents to consist in part of lists or choices in lists. For example, an address can have a state or region property where the value is one in a predefined list of choices. That is a 1-n relationship. A n-n relationship could be for example a list of commercial rewards that a customer can benefit from. Orchard does of course provide support for those scenarios. This topic is going to walk you through the creation of such contents.


# Building a _1-N_ Relationship

The model that we're going to build here consists of an Address part that can be attached for example to a Customer content type. The address part has a street address, a zip code, a city name and a state. The state is what we are going to model as a 1-n relationship to a table of states.

> Note: this is clearly over-normalized, as a state in an address would usually be sufficiently well represented by a simple two-letter state code. The UI can then take care of representing the choice of that code as a constrained choice in a list of states. We are not claiming what we are building here is the correct way to represent a state in an address, but that the process exposed here is representative of what you'd follow to build a real-world 1-n association in Orchard.

## Modeling the Address Part

Here is the code for the `Address` part:

    
    using Orchard.ContentManagement;
    
    namespace RelationSample.Models {
        public class AddressPart : ContentPart<AddressPartRecord> {
            public string Address {
                get { return Retrieve(r => r.Address); }
                set { Store(r => r.Address, value); }
            }
            
            public string City {
                get { return Retrieve(r => r.City); }
                set { Store(r => r.City, value); }
            }
            
            public StateRecord State {
                get { return Retrieve(r => r.StateRecord); }
                set { Store(r => r.StateRecord, value); }
            }
            
{'fraction_non_alphanumeric': 0.05040371910937118, 'fraction_numerical': 0.0019574259848299485, 'mean_word_length': 2.5029991431019707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4259401', 'n_tokens_mistral': 985, 'n_tokens_neox': 946, 'n_words': 572}