public void Save(T entity, int tenantId) { ISession session = NHibernatePersistencyService.GetTenantSession(tenantId); session.EnableFilter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterName).SetParameter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterParam, tenantId); session.SaveOrUpdate(entity); session.Flush(); session.Close(); }
public T Get(object id, int tenantId) { ISession session = NHibernatePersistencyService.GetTenantSession(tenantId); session.EnableFilter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterName).SetParameter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterParam, tenantId); T obj = session.Get <T>(id); session.Close(); return(obj); }
public int GetCount(DetachedCriteria criteria, int tenantId, params Order[] orders) { ISession session = NHibernatePersistencyService.GetTenantSession(tenantId); session.EnableFilter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterName).SetParameter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterParam, tenantId); ICriteria executableCriteria = GetExecutableCriteria(criteria, orders, session); executableCriteria.SetProjection(Projections.CountDistinct("Id")); int result = executableCriteria.UniqueResult <int>(); session.Close(); return(result); }
public ICollection <T> FindAll(DetachedCriteria criteria, int firstResult, int maxResults, int tenantId, params Order[] orders) { ISession session = NHibernatePersistencyService.GetTenantSession(tenantId); session.EnableFilter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterName).SetParameter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterParam, tenantId); ICriteria executableCriteria = GetExecutableCriteria(criteria, orders, session); executableCriteria.SetFirstResult(firstResult); executableCriteria.SetMaxResults(maxResults); ICollection <T> result = executableCriteria.List <T>(); session.Close(); return(result); }
public void StartSession(int tenantId) { session = NHibernatePersistencyService.GetTenantSession(tenantId); //Add Tenant Filter session.EnableFilter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterName).SetParameter(HirePro.Framework.Core.Common.Constants.MultiTenantFilterParam, tenantId); }
//private ISession _hireProSession; //public ISession HireProSession //{ // get { return _hireProSession; } //} /* * public NHibernateUnitOfWorkAdapter(UnitOfWorkAdapter previous):base(previous) * { * * } */ //private const int defaultTenantId = 1; protected override void Initialize() { try { string action = ServerContext.GetActionName(); int tenantId = ServerContext.GetTenantId(); int targetTenantId = 0; try { targetTenantId = ServerContext.GetTargetTenantId(); } catch { } if (targetTenantId != 0) { tenantId = targetTenantId; } #region Commented //if (NHibernatePersistencyService.TenantSessionFactories.Count >1) //{ // try // { // _session = NHibernatePersistencyService.TenantSessionFactories[tenantId].OpenSession(); // } // catch(System.Exception ex) // { // _session = NHibernatePersistencyService.TenantSessionFactories[defaultTenantId].OpenSession(); // } //} //else //{ // _session = NHibernatePersistencyService.SessionFactory.OpenSession(); //} //_session.FlushMode = FlushMode.Commit; #endregion IInterceptor interceptor = null; try { interceptor = HirePro.Framework.AppServer.Container.ObjectBuilder.Get <IInterceptor>("NHibernate_Interceptor_" + action); } catch (System.Exception e) { //Ignore Castle.Microkernel.ComponentNotFoundException } if (interceptor == null) { _session = NHibernatePersistencyService.GetTenantSession(tenantId); } else { _session = NHibernatePersistencyService.GetTenantSession(tenantId, interceptor); } //code to use session in WCF if (OperationContext.Current != null) { CurrentSessionContext context = new CurrentSessionContext(); context.Session = _session; OperationContext.Current.Extensions.Add(context); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } }