I was wondering is there a way to join two tables with two non primary key columns without creating a view? I have a table called 'Make' with columns of 'Name' and 'Year' that I want to join with another table called 'Style' with columns 'MakeName' and 'MakeYear'. One 'Make' can have many 'Style'. Here are the entities that I have created so far:
public class Make
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Year { get; set; }
public virtual IList<Style> Styles { get; set; }
}
public class Style
{
public virtual int Id { get; set; }
public virtual string MakeName { get; set; }
public virtual string MakeYear { get; set; }
public virtual string Class { get; set; }
public virtual Make Make { get; set; }
}
Also these are the class maps I have so far:
public class MakeMap : ClassMap<Make>
{
public MakeMap()
{
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Year);
// Bad mapping...
//HasManyToMany(x => x.Styles).Table("Make").AsBag()
.ParentKeyColumn("MakeName")
.ChildKeyColumn("MakeYear").Cascade.All();
Table("Make");
}
}
public class StyleMap : ClassMap<Style>
{
public StyleMap()
{
Id(x => x.Id);
Map(x => x.Class);
Map(x => x.MakeName);
Map(x => x.MakeYear);
// Ends up overwriting the "MakeName" column
References(x => x.Make).Column("MakeName").PropertyRef("Name").
Column("MakeYear").PropertyRef("Year");
Table("Style");
}
}
Thanks!