コード例 #1
0
        /// <summary>
        /// Gets the single item.
        /// </summary>
        /// <param name="filters">The filters.</param>
        /// <returns>A value of type T.</returns>
        public T GetSingleItem(params SqlFilter[] filters)
        {
            if ((filters == null) || (filters.Length == 0))
            {
                throw new ArgumentNullException("filters");
            }

            if (Connection == null)
            {
                throw new InvalidOperationException("must set connection before calling GetSingleItem()");
            }

            DbCommand command = PrepCommandForSelect(string.Empty, FillMethod.FilterArray, filters);

            SqlDialect.OptimizeSelectSingleCommand(command);

            return(GetSingleItem(command));
        }
コード例 #2
0
        /// <summary>
        /// Gets the single item.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>A value of type T.</returns>
        public T GetSingleItem(string filter, params object[] parameters)
        {
            if (string.IsNullOrEmpty(filter))
            {
                throw new ArgumentNullException("filter");
            }

            if (Connection == null)
            {
                throw new InvalidOperationException("must set connection before calling GetSingleItem()");
            }

            DbCommand command = PrepCommandForSelect(filter, FillMethod.FilterText, parameters);

            SqlDialect.OptimizeSelectSingleCommand(command);

            return(GetSingleItem(command));
        }
コード例 #3
0
        public T GetSingleItem(Expression <Func <T, bool> > filterExpression)
        {
            if (Connection == null)
            {
                throw new InvalidOperationException("must set connection before calling GetSingleItem()");
            }

            var parser = new WhereExpressionParser <T>(DataMap, SqlDialect)
            {
                UseQuotedIdentifier = CommandBuilder.UseQuotedIdentifier
            };
            var result = parser.Parse(filterExpression);

            DbCommand command = PrepCommandForSelect(result.SqlText, FillMethod.FilterText, result.Parameters);

            SqlDialect.OptimizeSelectSingleCommand(command);

            return(GetSingleItem(command));
        }