1
votes

I have an entity, called "Competition"

In Competition, I have a property:

IEnumerable<string> EventCodes {get;set;}

What I'm trying to do, is a subselect when mapping this Excerpt from my mapping file:

public CompetitionMap()
{
    Id(x => x.Id);

    Map(x => x.DisciplineCodes)
        .Formula("(SELECT DISTINCT DisciplineCode 
            from tblSomeOtherTable WHERE EventID = [ID])");

    Table("tblCompetitions");
}

However, this is throwing this error:

{"Could not determine type for: System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, for columns: NHibernate.Mapping.Formula( (SELECT DISTINCT EventCode from tblSomeOtherTable WHERE EventID = [ID]) )"}

It's worth mentioning that tblSomeOtherTable isn't mapped, nor will it be.

What have I missed?

1

1 Answers

1
votes

Try changing your 'IEnumerable' to 'ICollection.' Once you've done that, change the Map to a HasMany with the following specifications:

HasMany(x => x.EventCodes)
            .Table("tblSomeOtherTable")
            .KeyColumn("EventID")
            .Element("DisciplineCode")
            .AsSet()
            .ReadOnly();

Of course, if the other table isn't actually called 'tblSomeOtherTable' (and I hope it isn't) then make that modification as well.

I've never actually used 'Element' but I think this should work.