Fluent NHibernate 将多行分组到集合属性
我有类似的类
public class Content
{
// ...
public virtual IList<Detail> { get; set; }
}
public class Detail
{
// ...
public virtual Content Content { get; set; }
public virtual string Name { get; set; }
}
public class TagDetail : Detail
{
public virtual Tag Value { get; set; }
}
public class TagCollectionDetail : Detail
{
public virtual IList<Tag> Value{ get; set; }
}
,我想将这些详细信息映射到表
Details -table
contentId name type tagId
1 Tag Tag 2
2 Tags TagCollection 1
2 Tags TagCollection 3
2 Tags TagCollection 6
是否可以使用 Fluent NHibernate 将多行分组到一个对象(以及如何)? 我知道像这样重复信息(Detail.Name、Detail.Type)是一件坏事,但搜索会容易得多。
或者我必须将其映射到两个表中?
Details -table
contentId name type tagId
1 Tag Tag 2
2 Tags TagCollection
DetailsCollection -table
detailId tagId
2 1
2 3
2 6
I have classes like
public class Content
{
// ...
public virtual IList<Detail> { get; set; }
}
public class Detail
{
// ...
public virtual Content Content { get; set; }
public virtual string Name { get; set; }
}
public class TagDetail : Detail
{
public virtual Tag Value { get; set; }
}
public class TagCollectionDetail : Detail
{
public virtual IList<Tag> Value{ get; set; }
}
and I would like to map those details to table
Details -table
contentId name type tagId
1 Tag Tag 2
2 Tags TagCollection 1
2 Tags TagCollection 3
2 Tags TagCollection 6
Is it possible to group multiple rows to one object with Fluent NHibernate (and how)?
I know it's a bad thing to repeat information (Detail.Name, Detail.Type) like that, but searching would be much easier.
Or do I have to map it into two tables?
Details -table
contentId name type tagId
1 Tag Tag 2
2 Tags TagCollection
DetailsCollection -table
detailId tagId
2 1
2 3
2 6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将其建模如下:
PK = 主键,FK = 外键。我将这些列设置为数字/整数类型,它会自动递增。对于没有主键的表,NHibernate 不能很好地工作(或者根本不可能)。
再想一想,我不明白为什么你有 TagDetail 和 TagCollectionDetail。 TagDetail 是 TagCollectionDetail 的特例,其中只有 1 个标签。我认为你可以摆脱 TagDetail。
I would model this as follows:
PK = Primary Key, FK = Foreign Key. I would set these columns to a number/integer type, which gets auto-incremented. NHibernate doesn't work very well (or at all maybe) with tables without primary keys.
Thinking about this even more, I don't understand why you have TagDetail and TagCollectionDetail. TagDetail is a special case of TagCollectionDetail, where there is only 1 tag. I think you can get rid of TagDetail.