【发布时间】:2009-07-11 20:58:00
【问题描述】:
给定以下固定域模型:
public class Sentence {
public int Id { get; private set; }
public string Author { get; set; }
public string[] Words { get; set; }
}
以及以下建议的规范化数据库架构:
create table Sentence (
Id int identity(1,1) not null primary key,
Author varchar(450)
)
create table Word (
Id int identity(1,1) not null primary key,
Value varchar(450) not null unique
)
create table Sentence_Word (
SentenceId int foreign key references Sentence (Id),
WordId int foreign key references Word (Id),
SortIndex int not null,
primary key (SentenceId, WordId),
unique (SentenceId, SortIndex)
)
您将如何创建 NHibernate 映射文件?
如果我们可以添加另一个域实体Word 然后将Sentence 上的Words 属性更改为Word[] 而不是string[](这将是标准的多对多实体关系),但属性的string[]类型是必需的,不能更改。
这个问题和another StackOverflow question类似,只是需要使用多对多的关系来进行适当的数据规范化(词的集合比较小,而组合成句子的组合很大),所以不是立即清楚如何应用标准的基于值的集合。
【问题讨论】:
标签: nhibernate nhibernate-mapping