c# - Mapping a collection to a subselect with Fluent nHibernate -
i've got class looks like:
public class competitor { public virtual int competitorid { get; set; } public virtual string firstname { get; set; } public virtual string lastname { get; set; } public virtual ienumerable<string> sportscompeted { get; set; } }
sportscompeted
list of sportids (strings) resolved so:
select distinct sportid results competitorid = xxx
how go mapping that?
looking @ hasmany can specify where
clause, don't think that's quite i'm looking in case?
i'm using fluent mappings, omitted brevity.
you should able .element()
. like:
hasmany(x => x.sportscompeted) .keycolumn("competitorid") .element("sportid") // can define element type second parameter .table("results");
more info:
mapping collection of strings nhibernate
fluent nhibernate automapping of list<string>?
edit:
let's have result
, sport
entities instead:
public class sport { public virtual int sportid { get; set; } // other properties } public class result : entity { public virtual resultid { get; set; } public virtual competitor competitor { get; set; } public virtual sport sport { get; set; } // other properties } public class competitor { public virtual int competitorid { get; set; } public virtual ilist<result> results { get; set; } // other properties }
your hasmany
this:
// this, need have result , sport classes mapped // property isn't necessary sports competed query hasmany(x => x.results) .keycolumn("competitorid") .table("results");
then use ie. linq results want:
var sports = session.query<result>() .where(x => x.competitor.competitorid = competitorid) .select(x => x.sport) // or .select(x => x.sport.sportid) .distinct();
Comments
Post a Comment