Also, this code will give you all entities in the first level cache (stored 
by the ISession):

public static IEnumerable<T> Local<T>(this ISession session, Status status)
{
        var impl = session.GetSessionImplementation();
        var pc = impl.PersistenceContext;
 
        foreach (T key in pc.EntityEntries.Keys.OfType<T>())
        {
                var entry = pc.EntityEntries[key] as EntityEntry;
 
                if (entry.Status == status)
                {
                        yield return (key);
                }
        }
}


Use Status.Saving for added entities and Status.Deleted for entities marked 
as deleted. If you change this status, NHibernate will act accordingly. If 
you want to just remove an entity from NHibernate's control, use 
ISession.Evict().

RP

On Wednesday, December 17, 2014 8:24:09 PM UTC, [email protected] 
wrote:
>
> On Wednesday, 17 December 2014 17:22:59 UTC, Ricardo Peres wrote:
>>
>> But why don't you use the built in IValidatable and/or ILifecycle 
>> interfaces, or the event system, have you tried?
>>
>
> Thanks - I hadn't discovered them.
>
> I might be able to use them, but our current validation is a little 
> different because we want to list all of the reasons that objects cannot be 
> saved rather than just the first (so we keep validating after finding the 
> first problem - but one problem is enough to prevent objects being saved). 
> I realise that sounds a little weird, but it's for UI reasons (so e.g. you 
> get red boxes against all the fields you've forgotten to fill in rather 
> than just the one). Hence why it's nice to iterate over all objects that 
> are changing. I've had a quick look through and I don't think I can do that 
> easily.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to