Skip to content

Instantly share code, notes, and snippets.

@hyrmn
Created March 22, 2011 17:09
Show Gist options
  • Save hyrmn/881599 to your computer and use it in GitHub Desktop.
Save hyrmn/881599 to your computer and use it in GitHub Desktop.
[HasMany(typeof(POSPhoto), Inverse = true, Access = PropertyAccess.FieldCamelcaseUnderscore, Cascade = ManyRelationCascadeEnum.All, Lazy = true, RelationType = RelationType.Set )]
public virtual IEnumerable<POSPhoto> Photos
{
get
{
return _photos.AsReadOnly();
}
}
public virtual void AddPhoto(POSPhoto photo)
{
photo.Item = this;
_photos.Add(photo);
}
public virtual void RemoveAllPhotos()
{
_photos.Clear();
}
item.RemoveAllPhotos();
item.AddPhoto(posPhoto);
item.Save();
Does not delete existing posphotos from db... wth?
@hyrmn
Copy link
Author

hyrmn commented Mar 22, 2011

So, the issue is that I was setting cascade=all and not cascade=alldeleteorphan.

The important distinction is that alldeleteorphan will remove any objects (not records) that no longer have a parent. In this case, it deletes anything from the db that was removed from the posphoto collection on positem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment