Created
March 22, 2011 17:09
-
-
Save hyrmn/881599 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.