database design - Deleting child objects in HasMany() NHibernate relationship -


i have product object references ordered list of specification objects. when product gets updated, associated list of specifications .clear()'d , rebuilt (not new'd.)

the problem cascade.all() when product updated, creates 20 new specification rows in database, abandoning 20 old ones. cascase.alldeleteorphans() throws error:

additional information: collection cascade="all-delete-orphan" no longer referenced owning entity instance: invax.core.models.product.specifications

although want happen.. it's true, collection of specifications no longer referenced product -- delete these, right? well, have tried inverse() allow specification objects handle relationship didn't work either. here current mappings throw aforementioned error.

product mapping:

public class productmap : classmap<product> {    public productmap ()    {       id(x => x.id);       map(x => x.catalogid).not.nullable();       map(x => x.name).not.nullable();       map(x => x.urlslug).not.nullable();       map(x => x.shortdescription).not.nullable();       map(x => x.description).not.nullable();       map(x => x.imagefilename);       hasmany(x => x.specifications).cascade.alldeleteorphan().keycolumn("productid");       references(x => x.category).column("category");    } } 

specification mapping:

class specificationmap : classmap<specification> {     public specificationmap()     {         id(x => x.id);         map(x => x.name);         map(x => x.value);         references(x => x.product).column("productreferenceid").cascade.all();     } } 

i open solution problem, including more robust database design or data organization. have stick lists because specifications ordered in specific way.

apparently late you, if 1 has problem.

you should set cascade cascade.alldeleteorphan() because cascade.all() not delete unreferenced child objects.

ayende: difference between cascades


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -