Hello all,

here are my two entities:

public class VideoCategory : BaseEntity<VideoCategory>
{
    private readonly Iesi.Collections.Generic.ISet<VideoFolder>
folders = new HashedSet<VideoFolder>();

    public VideoCategory()
    {

    }

    public VideoCategory(string name)
    {
        Name = name;
    }

    public string Name { get; set; }

    public IEnumerable<VideoFolder> Folders { get { return
folders; } }
}

public class VideoFolder : BaseEntity<VideoFolder>
{
    private string path;
    private readonly Iesi.Collections.Generic.ISet<VideoFile> videos =
new HashedSet<VideoFile>();

    public VideoFolder()
    {

    }

    public VideoFolder(string path)
    {
        Path = path;
    }

    public string Path { get; set; }
    public string Name { get; private set; }
}

There is a Many-To-One relationship from VideoFolder to VideoCategory,
with a Cascade.AllDeleteOrphan.

Here is how the problem happens:

I create a new instance of VideoCategory, and save it in SessionA.
Once created, the id of this category is published to another view-
model, which queries the database to load the entity, in SessionB.

In SessionB, I create a new VideoFolder, add it to the category, and I
update the category in SessionB.

Now back in SessionA, if I then want to delete VideoCategory, I have
this exception:

"The primary key value cannot be deleted because references to this
key still exist"

I think it's normal, because SessionA doesn't know that the category
now has some folders.

I've added a step which allows the first view-model, owning SessionA,
to update the category after it has been updated by SessionB, before
it deletes the category, and in that step:

* I've tried to call Session.Merge, but I have : NonUniqueException :
a different object with the same identifier value was already
associated with the session:1, of entity VideoCategory
* I've tried to evict the category, then merge it, but I have the same
exception.

How can I resolve my problem?

Thanks in advance

Michael

PS: if I add the category, then add a folder to the category, then
close the view-model, then open it again and delete the category, I
don't have the exception

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to