Ejemplo n.º 1
0
        public static bool IsTransient(ISession session, object obj)
        {
            ISessionFactoryImplementor sessionFactoryImpl = session.SessionFactory as ISessionFactoryImplementor;
            // Here `obj` may be an instance of an NHibernate proxy, so we cannot simply use
            // `obj.GetType().FullName`, we need to get the real underlying type.
            var persister = new SessionFactoryHelper(sessionFactoryImpl)
                            .RequireClassPersister(NHibernateUtil.GetClass(obj).FullName);
            bool?yes = persister.IsTransient(obj, (ISessionImplementor)session);

            return(yes ?? default(bool));
        }
 public bool?IsPersisted(object obj, ISession session)
 {
     try
     {
         var sessionFactoryImpl = (ISessionFactoryImplementor)session.SessionFactory;
         var persister          = new SessionFactoryHelper(sessionFactoryImpl).RequireClassPersister(obj.GetType().FullName);
         return(!persister.IsTransient(obj, (ISessionImplementor)session));
     }
     catch (Exception)
     {
         return(null);
     }
 }