Confusion about Linking Two Content Types

Topics: Administration, General
Jan 21, 2014 at 5:59 AM
I am building module where i created two content types "Customer" and "Courses". Each Customer can have one or multiple courses assigned. I am confused how can i interlink them? do i need to create another content type e.g. "CustomerCourses" where i would save "CustomerID" and "CourseID" ?

Migration.cs

  public int Create() {
            // Creating table CoursePartRecord
            SchemaBuilder.CreateTable("CoursePartRecord", table => table
                .ContentPartRecord()
                .Column("Name", DbType.String)
                .Column("Description", DbType.String)
                .Column("Location", DbType.String)
                .Column("Category", DbType.String)
                .Column("StartDate", DbType.DateTime)
                .Column("EndDate", DbType.DateTime)
                .Column("Fees", DbType.Double)
                .Column("HomeAddress", DbType.String)
                .Column("WorkAddress", DbType.String)
                .Column("HomePhone", DbType.String)
                .Column("CellPhone", DbType.String)
                .Column("WorkPhone", DbType.String)
                .Column("Website", DbType.String)
                .Column("SkypeID", DbType.String)
                .Column("DOB", DbType.DateTime)
                .Column("BCUClassification", DbType.String)
                .Column("HealthDecleration", DbType.String)
                .Column("FacebookURL", DbType.String)
                .Column("Twitter", DbType.String));

            ContentDefinitionManager.AlterPartDefinition("CoursePart",
              builder => builder.Attachable());

            // Creates Content Type "Course" 
            // adds CoursePart and CommonPart Content part Types to "Course"
            ContentDefinitionManager.AlterTypeDefinition("Course", cfg => cfg
              .WithPart("CoursePart")
              .WithPart("CommonPart")       
              .Creatable());

            //Creates CustomerPartRecord table
            SchemaBuilder.CreateTable("CustomerPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("FirstName", c => c.WithLength(50))
                .Column<string>("LastName", c => c.WithLength(50))
                .Column<string>("Title", c => c.WithLength(10))
                .Column<DateTime>("CreatedUtc")
                );

            ContentDefinitionManager.AlterPartDefinition("CustomerPart", part => part
                .Attachable(false)
                );

            //Create Content Type "Customer" and adds "CustomerPart" and "UserPart" Content Part Types to it.
            ContentDefinitionManager.AlterTypeDefinition("Customer", type => type
                .WithPart("CustomerPart")                
                .WithPart("UserPart")                
                );

            return 1;
        }
Jan 21, 2014 at 9:05 AM
Its a bit old, bit it might point you in the right direction:
http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations
Jan 24, 2014 at 6:05 AM
@rudolphk thanks for the help. I have read link you mentioned. With reference to "Reward" content part, they have hard-coded list of rewards in driver as "RewardProgramRecord". so when this reward is attached to some content item, user will be able to select only those rewards. Basically i need to create single entry as "RewardProgramRecord" but i cant figure out how can i do that ?
        private readonly IEnumerable<RewardProgramRecord> _rewardPrograms =
            new List<RewardProgramRecord> {
                new RewardProgramRecord {Name = "Senior", Discount = 0.05},
                new RewardProgramRecord {Name = "Family", Discount = 0.10},
                new RewardProgramRecord {Name = "Member", Discount = 0.15},
            };