通过两个非主键列连接的流畅 Nhibernate 映射
我想知道是否有一种方法可以在不创建视图的情况下连接两个具有两个非主键列的表?我有一个名为“Make”的表,其中包含“Name”和“Year”列,我想将其与另一个名为“Style”的表连接,其中包含“MakeName”和“MakeYear”列。一种“品牌”可以有多种“风格”。 以下是我迄今为止创建的实体:
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; }
}
另外,这些是我迄今为止拥有的类映射:
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");
}
}
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
3 个选项,我更喜欢第一个
选项:
更改
数据库架构
以将makeid
而不是名称和年份包含到样式表中Option
3 options where i would prefere the first
Option:
change the
db schema
to include the makeid
instead of the name and year into the style tableOption