你应该能够做到这一点.Element()
。就像是:
HasMany(x => x.SportsCompeted)
.KeyColumn("CompetitorId")
.Element("SportID") // You can define element type as second parameter
.Table("results");
更多信息:
使用 NHibernate
Fluent NHIbernate 自动映射 List<string>? 映射字符串集合?
编辑:
假设你有你的Result
和Sport
实体:
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
}
你HasMany
现在看起来像这样:
// For this, you would need to have Result and Sport classes mapped
// This property isn't necessary for your Sports Competed query
HasMany(x => x.Results)
.KeyColumn("CompetitorId")
.Table("results");
然后你可以使用ie。Linq 得到你想要的结果:
var sports = session.Query<Result>()
.Where(x => x.Competitor.CompetitorId = competitorId)
.Select(x => x.Sport) // Or .Select(x => x.Sport.SportId)
.Distinct();