Given the following fixed domain model:
public class Sentence {
public int Id { get; private set; }
public string Author { get; set; }
public string[] Words { get; set; }
}
And the following proposed normalized database schema:
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)
)
How would you create the NHibernate mapping file?
This would be easy if we could add another domain entity Word
and then change the Words
property on Sentence
to Word[]
instead of string[]
(it'd be a standard many-to-many entity relationship), but the string[]
type for the property is required and cannot be changed.
This problem is similar to another StackOverflow question, except a many-to-many relationship needs to be used for proper data normalization (the set of words is relatively small while the combination of them into Sentences is huge), so it's not immediately clear how the standard value-based collections can be applied.