Esempio n. 1
0
        public Boolean GetIsDefault(Contractor obj)
        {
            Contractor contractorAlias = null;
            Contractor contractor      = NHSession.QueryOver(() => contractorAlias)
                                         .Where(() => contractorAlias.ID == obj.ID)
                                         .SingleOrDefault();

            NHSession.Evict(contractor);
            return(contractor.IsDefault);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize Collection or Proxy
        /// 从外部Initialize,默认LockMode=Write。如果为None,不会写数据库。Lock后要先Evict
        /// </summary>
        /// <param name="proxy"></param>
        /// <param name="owner"></param>
        /// <param name="session"></param>
        internal static void Initialize(object proxy, object owner, NHibernate.ISession session)
        {
            if (null == proxy)
            {
                return;
            }

            if (!NHibernateUtil.IsInitialized(proxy))
            {
                if (proxy is INHibernateProxy)
                {
                    session.Lock(proxy, NHibernate.LockMode.None);
                    NHibernateUtil.Initialize(proxy);
                    session.Evict(proxy);
                }
                else if (proxy is IPersistentCollection)
                {
                    bool b = session.Contains(owner);
                    if (!b)
                    {
                        session.Lock(owner, NHibernate.LockMode.None);
                    }
                    NHibernateUtil.Initialize(proxy);
                    if (!b)
                    {
                        session.Evict(owner);
                    }
                }

                //if (proxy is INHibernateProxy || proxy is IPersistentCollection)
                //{
                //    if (proxy is INHibernateProxy) session.Lock(proxy, NHibernate.LockMode.None);
                //    else if (!session.Contains(owner)) session.Lock(owner, NHibernate.LockMode.None);

                //    NHibernateUtil.Initialize(proxy);
                //}
            }
        }