c# - NHibernate doesn't update many-to-many join table -


i have 3 tables @ database: images, imagetags, tags. images , tags have many-to-many relationship via imagestags table. images entity:

public class image {     public virtual int id { get; set; }     public virtual string name { get; set; }     public virtual ilist<tag> tags { get; set; } } 

tags entity:

public class tag {     public virtual int id { get; set; }     public virtual string name { get; set; } } 

images map:

public imagemap() {     table("images");     id(x => x.id).generatedby.identity();     map(m => m.name).length(100).not.nullable();      hasmanytomany(f => f.tags).table("imagetags")        .lazyload().inverse().cascade.saveupdate();  } 

tags map:

public tagmap() {     table("tags");     id(x => x.id).generatedby.identity();     map(m => m.name).length(100).not.nullable(); } 

when i'm trying update image, join table imagestag doesn't update, other image properties (name) updates.

    public void update (image image)     {         session.saveorupdate(image);         session.flush();     } 

looking help, how update join table.

the problem in mapping, explicitly in .inverse() setting

public imagemap() {     ...     hasmanytomany(f => f.tags)        .table("imagetags")        .lazyload()        .inverse()         // wrong, remove        .cascade.saveupdate();  } 

why? setting there cases, when mapp both ends, e.g. if on tag side:

public tagmap() {     ...     hasmanytomany(f => f.images)        .... } 

in case, have both ends, mapped, , must instruct nhibernate, end master. in fact, setting .inverse() - set slave

so, because in our case, not have other end managing pairing table... cannot use inverse setting. that's it. remove it, nhibernate behave we'd expect


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -