This project is read-only.

Creating 1-N and N-N Relations Tutorial question

Topics: Customizing Orchard, Writing modules
Nov 20, 2011 at 10:41 PM

In the tutorial there is a step where he populates the State Record table with list of States using an IEnumerable List in the Migration code file:


"Because the list of states is going to be relatively stable, I did not make them content items (although that would be entirely possible with just a little more work).

Instead, I'm populating the table with a list of states right in the migration code. The migration class has a reference to the state repository:

private readonly IRepository<StateRecord> _stateRepository;
public RelationSampleDataMigration(IRepository<StateRecord> stateRepository) {
    _stateRepository = stateRepository;

It also has the list of states to add to the database:

private readonly IEnumerable<StateRecord> _states =
new List<StateRecord> {
    new StateRecord {Code = "AL", Name = "Alabama"},
    new StateRecord {Code = "AK", Name = "Alaska"},
    new StateRecord {Code = "WS", Name = "Western Australia"},



My question is about this line in the tutorial:


 "I did not make them content items (although that would be entirely possible with just a little more work)."

What does he mean "Make them into content items"?

How do you  make data into Content Items programmatically? 



Nov 21, 2011 at 12:45 AM

You can model any type of data as a Content Item, by creating a new content type and appropriate parts to represent the data. It means the data can be extended with more content parts, instead of being a fixed single table.

Nov 21, 2011 at 1:44 AM

So basically just make a content type. add fields, fill out the fields and publish the page? The data gets dumped into whatever content tables they get dumped into? Thats cool. I thought it was trying to say you can populate a table with data and somehow make them content items while doing so in code.