Example #1
0
        /// <summary>
        /// Constructor. Explicitly set database connection.
        ///   Use .Construct() instead. Cannot use new()
        ///   due to needing ConnectionStringName() attribute data before construction
        /// </summary>
        protected SaveableDatabase()
            : base(ReadOnlyDatabase <TEntity> .Construct().ConnectionString)
        {
#if (DEBUG)
            ThrowException = true;
#endif
        }
Example #2
0
        /// <summary>
        /// Retrieves data with purpose of displaying results over multiple pages (i.e. in Grid/table)
        /// </summary>
        /// <param name="whereClause">Expression for where clause</param>
        /// <returns></returns>
        public IQueryable <TEntity> GetByWhere(Expression <Func <TEntity, Boolean> > whereClause)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            try
            {
                returnValue = (whereClause != null) ? db.Data.Where <TEntity>(whereClause) : db.Data;
            }
            catch (Exception ex)
            {
                ExceptionLogger.Create(ex, typeof(TEntity), "ReadOnlyDatabase.GetByWhere()");
            }

            return(returnValue);
        }
Example #3
0
        /// <summary>
        /// Instantiates and initializes.
        ///  Do not allow new() due to constructor needing to instantiate ReadOnlyDatabase to get the attributes
        /// </summary>
        /// <returns></returns>
        public static ReadOnlyDatabase <TEntity> Construct()
        {
            var returnValue         = new ReadOnlyDatabase <TEntity>();
            var configManager       = new ConfigurationManagerFull();
            var configConnectString = new ConnectionStringSafe();

            configConnectString = configManager.ConnectionString(returnValue.GetAttributeValue <ConnectionStringName>(ConnectionStringName.DefaultValue));
            if (configConnectString.ToEF(typeof(TEntity)) == TypeExtension.DefaultString)
            {
                throw new System.Exception("Connection string could not be found. A valid connection string required for data access.");
            }
            else
            {
                returnValue = new ReadOnlyDatabase <TEntity>(configConnectString.ToEF(typeof(TEntity)));
            }

            return(returnValue);
        }
Example #4
0
        /// <summary>
        /// Retrieves data with purpose of displaying results over multiple pages (i.e. in Grid/table)
        /// </summary>
        /// <param name="whereClause">Expression for where clause</param>
        /// <param name="orderByClause">Expression for order by clause</param>
        /// <param name="pageSize">Size of each result</param>
        /// <param name="pageNumber">Page number</param>
        /// <returns></returns>
        public IQueryable <TEntity> GetByPage(Expression <Func <TEntity, Boolean> > whereClause, Expression <Func <TEntity, Boolean> > orderByClause, int pageSize, int pageNumber)
        {
            var db = ReadOnlyDatabase <TEntity> .Construct();

            var datastore = ReadOnlyDatabase <TEntity> .Construct();

            var returnValue = default(IQueryable <TEntity>);

            try
            {
                returnValue = (datastore.Data).AsQueryable();
                returnValue = (whereClause != null) ? returnValue.Where <TEntity>(whereClause).AsQueryable() : returnValue;
                returnValue = (orderByClause != null) ? returnValue.OrderBy(orderByClause).AsQueryable() : returnValue;
                returnValue = (pageNumber > 0 && pageSize > 0) ? returnValue.Skip((pageNumber * pageSize)).Take(pageSize).AsQueryable() : returnValue;
            }
            catch (Exception ex)
            {
                ExceptionLogger.Create(ex, typeof(TEntity), "ReadOnlyDatabase.GetByPage()");
            }

            return(returnValue);
        }