Example #1
0
        public Guid?SetGuidFromInt(BodyArchitect.Service.Model.GetProfileInformationCriteria obj)
        {
            ISession session = NHibernateContext.Current().Session;

            Guid?guid = null;

            using (var tx = session.BeginTransaction())
            {
                string type = obj.GetType().Name;
                //var count = session.CreateSQLQuery("SELECT COUNT(*) FROM idconvertion i WHERE i.type = :type").SetString("type", type).UniqueResult();
                //var result = session.CreateQuery("INSERT INTO idconvertion VALUES (:count, :type, :guid)")
                //    .SetInt32("count", (int)count+1).SetGuid("guid", obj.GlobalId).SetString("type", type).UniqueResult();
                //var count = session.QueryOver<IdConvertion>().Where(a => a.Type == obj.GetType().Name).RowCount();
                IdConvertion temp = new IdConvertion();
                temp.GuidId = Guid.NewGuid();
                if (obj.UserId != null)
                {
                    temp.IntId = (int)obj.UserId;
                }
                else
                {
                    var count = session.QueryOver <IdConvertion>().Where(a => a.Type == obj.GetType().Name).RowCount();
                    temp.IntId = ++count;
                }
                temp.Type = obj.GetType().Name;
                session.Save(temp);
                tx.Commit();

                guid = temp.GuidId;
            }
            return(guid);
        }
Example #2
0
        public Guid?GetGuidFromInt(BodyArchitect.Service.Model.GetProfileInformationCriteria obj)
        {
            ISession session = NHibernateContext.Current().Session;
            Guid?    guid;

            using (var tx = session.BeginTransaction())
            {
                var result = session.QueryOver <IdConvertion>().Where(b => b.IntId == obj.UserId).And(c => c.Type == obj.GetType().Name).SingleOrDefault();
                tx.Commit();
                if (result != null)
                {
                    guid = result.GuidId;
                }
                else
                {
                    guid = null;
                }
            }
            return(guid);
        }