Search code examples
castle-activerecord

Castle Activerecord. Two collections of the same class


I want to have two collections of same class items in Activerecord. How to map this?

class Project
{
 [HasMany]
 IList<Resource> Resources { get; set; }

 [HasMany]
 IList<Resource> DepartmentResources { get; set; }
}

public class Resource
{
 [BelongsTo ???
}

Solution

  • Use the ColumnKey property, e.g.:

    [HasMany(ColumnKey="res")]
    IList<Resource> Resources { get; set; }
    
    [HasMany(ColumnKey="deptres")]
    IList<Resource> DepartmentResources { get; set; }
    
    ...
    
    public class Resource {
      [BelongsTo("res")]
      Project Project {get;set;}
    
      [BelongsTo("deptres")]
      Project DeptProject {get;set;}
    }