1
public class Template
{
    public int TemplateID { get; set; }
    public string Name { get; set; }
    public IList<int> DocIds { get; set; }
}

public class TemplateMap : ClassMap<Template>
{
    public TemplateMap ()
    {
        Id(x => x.ID).GeneratedBy.Identity();
        Map(x => x.Name);

        WithTable("Template");
        DiscriminateSubClassesOnColumn<string>("TemplateID ").SubClass<Template>("not null", m => { });
    }
}

There are two tables: Template and TemplateDocument. They are as follows:

Template
-------------------------
TemplateID int
Name varchar(255)

TemplateDocument
-------------------------
TemplateID int
DocID int

I would like to just return the Template object filled with the DocIDs from the TemplateDocument table for each template (by TemplateID). Is that possible? How do I go about setting up the mapping for this? It seems so simple, yet I can't seem to get this mapping to work.

Thanks.

dotjoe
  • 26,242
  • 5
  • 63
  • 77
John M.
  • 11
  • 1
  • Do you also have `TemplateDocument` mapped? – dotjoe Feb 22 '11 at 22:34
  • If you really want to map a list of ints, check this answer http://stackoverflow.com/questions/1942001/fluent-nhibernate-automapping-of-liststring/1949495#1949495 – dotjoe Feb 22 '11 at 22:37
  • Yes, I meant to enter `ClassMap – John M. Feb 23 '11 at 04:42
  • Wow, be careful if you are also mapping the TemplateDocument. If you manipulate the `DocIds` property it is possible you will blow up any TemplateDocuments as you'll effectively be changing their ids. – fostandy Feb 23 '11 at 13:39

0 Answers0