Migration for 1-N relationship problem

Topics: Customizing Orchard, General
May 21, 2014 at 9:48 AM
Hi!

I want to create a record class that should be referenced by other record classes. It's like Address and State records, but in my case this State should by part not only for Address.
For example I have Company record and I want it to be referenced by my Customer record, Instruction record and some other record classes.
Of course I can create one big migration class which will create all of this record tables, but I think it would be better to have multiple migration classes (per record class) for better maintainability.
But in this case we have another problem: we don't have control over migrations execution order.

So I don't have any options here? I have to put all my tables creation code in one migration class?
May 21, 2014 at 10:48 AM
In short I would say : if multiple records are part of the same 'logical' set, you should include them in the same migration.

Btw, you could do something like we did @ migrations to keep the file a bit cleaner:

http://pastebin.com/n2FtEn1d
May 23, 2014 at 1:43 PM
Edited May 23, 2014 at 1:44 PM
Thanks for the answer, AimOrchard!

Well, I've take a look more attentively at the new feature of Orchard 1.8 - storing data using Infoset.
According this article I don't have to create additional tables for my parts, I just need to update my getter and setters to use Store and Retrieve mehtods. All my data now can be stored in one table. I was happy!
Until I tried to store there more complex type than just dates, strings etc.
For example, I have this content part:
    public partial class CompanyPart: ContentPart
    {
        [Required]
        public String ShortName 
        { 
            get { return this.Retrieve(x=>x.ShortName); }
            set { this.Store(x=>x.ShortName, value); }
        }
        [Required]
        public String Name 
        { 
            get { return this.Retrieve(x=>x.Name); }
            set { this.Store(x=>x.Name, value); }
        }
    }
and I want it to be a part of my second part, like this:
    public partial class ApplicationFormTypePart: ContentPart
    {
        [Required]
        public String Name 
        { 
            get { return this.Retrieve(x=>x.Name); }
            set { this.Store(x=>x.Name, value); }
        }
        public CompanyPart Company 
        { 
            get { return this.Retrieve(x=>x.Company); }
            set { this.Store(x=>x.Company, value); }
        }
    }
But when I'm trying to save ApplicationFormTypePart, I've got an exception
System.NotSupportedException: Could not handle type CompanyPart
at Orchard.ContentManagement.XmlHelper.ToString[T](T value) in d:\work\Cabinet\src\Orchard\ContentManagement\XmlHelper.cs:line 223
at Orchard.ContentManagement.XmlHelper.Attr[T](XElement el, String name, T value) in d:\work\Cabinet\src\Orchard\ContentManagement\XmlHelper.cs:line 56
at Orchard.ContentManagement.InfosetHelper.Store[TProperty](InfosetPart infosetPart, String partName, String name, TProperty value, Boolean versioned) in d:\work\Cabinet\src\Orchard\ContentManagement\InfosetHelper.cs:line 111
at Orchard.ContentManagement.InfosetHelper.Store[TPart,TProperty](TPart contentPart, Expression`1 targetExpression, TProperty value, Boolean versioned) in d:\work\Cabinet\src\Orchard\ContentManagement\InfosetHelper.cs:line 91
Perhaps I miss something or maybe there is another way to get what I want?