コード例 #1
0
        public int?SetIntFromGuid(BodyArchitect.Service.V2.Model.BAGlobalObject obj)
        {
            ISession session = NHibernateContext.Current().Session;

            int?intId = 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 = obj.GlobalId;
                temp.IntId  = ++count;
                temp.Type   = obj.GetType().Name;
                session.Save(temp);
                //session.Save(
                tx.Commit();

                intId = temp.IntId;
            }
            return(intId);
        }
コード例 #2
0
        public Guid?SetGuidFromInt(int?id, object 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 (id != null)
                {
                    temp.IntId = (int)id;
                }
                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);
        }