c# - Cascading with Castle ActiveRecord HasAndBelongsToMany's -
I have trouble does not get a lot of wide using Castle ActiveRecord / NHibernate removed through a HasAndBelongsToMany relationship.
I have a lot of tags and they are connected to a table called PhotoHasTag, which has only one photo ID and tag ID. When I delete a photo, I want to remove all related phototag tags and delete any orphan tag as well.
Now I have my Photo class setup like this:
[ActiveRecord (table = "photo")] Public class photo {[PrimaryKey (column = "PHOTOID" , Generator = Castle.ActiveRecord.PrimaryKeyType.Identity)] Public Virtual Integer ID {Get; Set; } [HasAndBelongsToMany (Table = "PhotoHasTag", ColumnKey = "PHOTOID", ColumnRef = "tagId", Lazy = true, Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)] public virtual IList & LT; Tag & gt; Tags {get; Set; }} and my tag class is setup very similarly:
[ActiveRecord (table = "tag")] public class photos {primary key (Column = "tag id", generator = castle.active record. Premium type type identity)] public virtual id id {receive; Set; } [HasAndBelongsToMany (Table = "PhotoHasTag", ColumnKey = "tagId", ColumnRef = "PHOTOID", Lazy = true)] public IList & LT; Photo & gt; Receive photos { Set; }} I will try to remove is an error I finally SQL Server picture:
conflicted with a delete statement reference obstacle "PhotoHasTag_FK1 ". I can move around in SQL Server by setting the Delete Rule cascade key, but then only PhotoHasTag be removed as they database if any orphaned Tags Will still stop
I'm considering taking care of a catalyst writing left more tags but I can be very happy if there is a way to setup my ActiveRecord mapping then delete the cascades below is.
Thanks in advance, I have stuck on it forever so I would appreciate any and all help
[HasAndBelongsToMany (table = "PhotoHasTag", Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, ColumnKey = "tagId", ColumnRef = "PHOTOID", Lazy:> you so Can specify the cascade behavior in characteristics such as = true)] Public IList & lt; Photo & gt; Receive photos { Set; } The document is probably more useful.
Comments
Post a Comment