Ejemplo n.º 1
0
        protected override void DoDeleteFromDatabase(
            UserProfileDataObject entity,
            LambdaExpression filterExpression,                                  // no longer used here - handled higher up the stack by dataprovider extensions
            IObjectsDataSet context,
            Parameters parameters)
        {
            var session  = NHibernateSessionController.GetCurrentSession();
            var toDelete = entity.ToORMEntity();

            session.Delete(toDelete);
        }
        public override IORMEntity ToORMEntity()
        {
            var session = NHibernateSessionController.GetCurrentSession();

            var result = new ORMGOUserGroup();

            CopyTo(result, session);

            // Ensure no copy of result (instance with same key) in session
            Evict(result, session);

            return(result);
        }
        private ORMGOGroup LoadGroup()
        {
            if (_Group != null)
            {
                return(_Group);
            }

            if (!HasForeignKeyForRelation_Group)
            {
                return(null);
            }

            var session = NHibernateSessionController.GetCurrentSession();

            return(session.Load <ORMGOGroup>(_GOGroupName));
        }
        private ORMGOUser LoadUser()
        {
            if (_User != null)
            {
                return(_User);
            }

            if (!HasForeignKeyForRelation_User)
            {
                return(null);
            }

            var session = NHibernateSessionController.GetCurrentSession();

            return(session.Load <ORMGOUser>(_GOUserId));
        }
        private IQueryable <ORMGOLoginHistory> Query(
            Expression <Func <ORMGOLoginHistory, bool> > selectPredicate,
            string dynamicFilterExpression,
            object[] dynamicFilterArguments,
            LambdaExpression compiledFilter,
            bool throwIfAccessDenied = false)
        {
            var session = NHibernateSessionController.GetCurrentSession();

            IQueryable <ORMGOLoginHistory> query = null;

            if (!String.IsNullOrWhiteSpace(dynamicFilterExpression))
            {
                Expression <Func <ORMGOLoginHistory, bool> > dynamicPredicate = null;

                query = session.Query <ORMGOLoginHistory>();

                if (selectPredicate != null)
                {
                    query = query.Where(selectPredicate);
                }

                dynamicPredicate = System.Linq.Dynamic.DynamicExpression.ParseLambda <ORMGOLoginHistory, bool>(dynamicFilterExpression, dynamicFilterArguments);

                if (dynamicPredicate != null)
                {
                    query = query.Where(dynamicPredicate);
                }
            }
            else
            {
                query = session.Query <ORMGOLoginHistory>();

                if (selectPredicate != null)
                {
                    query = query.Where(selectPredicate);
                }
            }

            return(ApplyCompileTimeFilterExpression(query, compiledFilter, throwIfAccessDenied));
        }
Ejemplo n.º 6
0
        /// Does the Save or Update through the ORM and returns an entity instance with any database generated PK assigned
        /// Note: We don't support databse generated composite keys - best avoided.
        private TENTITY SaveToDatabaseThroughORM(TENTITY entity, bool deepMapping)
        {
            TENTITY result = null;

            var session = NHibernateSessionController.GetCurrentSession();

            if (entity.ObjectsDataSet.GetAllObjects().Count(o => o.IsDirty || o.IsNew) == 0)
            {
                return(entity);
            }
            else
            {
                object newPK = null;

                if (deepMapping)
                {
                    // Deep mapping is implemented as a dependency graph resolution via ISaveDependencyResolver
                    // Note: This means if a client application has a specific known dependency that the default implemenation fails to resolve, you can hook your own implementation in here
                    // (e.g. call the default one, and then adjust the result)
                    var saveList = ApplicationSettings.Resolve <ISaveDependencyResolver>().Sort(entity.ObjectsDataSet);
                    foreach (var obj in saveList)
                    {
                        var resultPk = SaveOrUpdateThroughORM(session, obj, isMainEntity: ReferenceEquals(obj, entity));
                        newPK = newPK ?? resultPk;
                    }
                }
                else
                {
                    newPK = SaveOrUpdateThroughORM(session, entity, isMainEntity: true);
                }

                if (newPK != null)
                {
                    result = (TENTITY)entity.Clone(recursive: false);
                    result.AssignPrimaryKey(newPK);
                }
            }

            return(result ?? entity);
        }
        ///
        /// Bridge to DataObject
        ///
        public virtual IDataObject ToDataObject(IObjectsDataSet dataset)
        {
            var session = NHibernateSessionController.GetCurrentSession();

            session.Evict(this);

            var x = new GOUserDataObject();

            SetProperties(x);

            x.IsDirty = x.IsNew = x.IsMarkedForDeletion = false;

            x.ObjectsDataSet = dataset;
            x.ObjectsDataSet.AddObjectIfDoesNotExist(x);

            // Deep-map prefetch relations
            if (PrefetchAssociations.HasPrefetchForEntity("GOUser", ApplicationSettings.Resolve <IDataProviderTransaction>()?.Parameters))
            {
                SetRelations(x);
            }

            return(x);
        }
Ejemplo n.º 8
0
        private IQueryable <ORMUserProfile> Query(
            Expression <Func <ORMUserProfile, bool> > selectPredicate,
            string dynamicFilterExpression,
            object[] dynamicFilterArguments,
            LambdaExpression compiledFilter,
            bool throwIfAccessDenied = false)
        {
            var session = NHibernateSessionController.GetCurrentSession();

            IQueryable <ORMUserProfile> query = null;

            if (!String.IsNullOrWhiteSpace(dynamicFilterExpression))
            {
                Expression <Func <ORMUserProfile, bool> > dynamicPredicate = null;
                // Special case for OneToOne PK -> FK side filtering, we need to override default inner join with an outer left join in order for the filter to work correctly
                if (dynamicFilterExpression.Contains("GOUser == null"))
                {
                    dynamicFilterExpression = dynamicFilterExpression.Replace("GOUser == null", "");

                    dynamicPredicate = String.IsNullOrWhiteSpace(dynamicFilterExpression)
                                                ? null
                                                : System.Linq.Dynamic.DynamicExpression.ParseLambda <ORMUserProfile, bool>(dynamicFilterExpression, dynamicFilterArguments);

                    var queryOver = session.QueryOver <ORMUserProfile>();

                    if (selectPredicate != null)
                    {
                        queryOver = queryOver.Where(selectPredicate);
                    }

                    if (dynamicPredicate != null)
                    {
                        queryOver = queryOver.Where(dynamicPredicate);
                    }

                    query = queryOver.Left.JoinQueryOver <ORMGOUser>(x => x.GOUser)
                            .List <ORMUserProfile>()
                            .Where(x => x.GOUser == null)
                            .AsQueryable();

                    query = ApplyCompileTimeFilterExpression(query, compiledFilter, throwIfAccessDenied);

                    return(query);
                }

                query = session.Query <ORMUserProfile>();

                if (selectPredicate != null)
                {
                    query = query.Where(selectPredicate);
                }

                dynamicPredicate = System.Linq.Dynamic.DynamicExpression.ParseLambda <ORMUserProfile, bool>(dynamicFilterExpression, dynamicFilterArguments);

                if (dynamicPredicate != null)
                {
                    query = query.Where(dynamicPredicate);
                }
            }
            else
            {
                query = session.Query <ORMUserProfile>();

                if (selectPredicate != null)
                {
                    query = query.Where(selectPredicate);
                }
            }

            return(ApplyCompileTimeFilterExpression(query, compiledFilter, throwIfAccessDenied));
        }
Ejemplo n.º 9
0
 protected void Application_End()
 {
     techLogger.Info("Application_End");
     NHibernateSessionController.CloseSessionFactory();
 }