Mapping a child collection without indexing based on database primary key or using bag
Posted
by Colin Bowern
on Stack Overflow
See other posts from Stack Overflow
or by Colin Bowern
Published on 2010-03-11T16:25:26Z
Indexed on
2010/03/11
17:49 UTC
Read the original article
Hit count: 550
nhibernate
|mapping
I have a existing parent-child relationship I am trying to map in Fluent Nhibernate:
[RatingCollection] --> [Rating]
Rating Collection has:
- ID (database generated ID)
- Code
- Name
Rating has:
- ID (database generated id)
- Rating Collection ID
- Code
- Name
I have been trying to figure out which permutation of HasMany makes sense here. What I have right now:
HasMany<Rating>(x => x.Ratings)
.WithTableName("Rating")
.KeyColumnNames.Add("RatingCollectionId")
.Component(c => { c.Map(x => x.Code);
c.Map(x => x.Name); );
It works from a CRUD perspective but because it's a bag it ends up deleting the rating contents any time I try to do a simple update / insert to the Ratings property. What I want is an indexed collection but not using the database generated ID (which is in the six digit range right now).
Any thoughts on how I could get a zero-based indexed collection (so I can go entity.Ratings[0].Name = "foo") which would allow me to modify the collection without deleting/reinserting it all when persisting?
© Stack Overflow or respective owner