Exemple #1
0
        public IList <TResult> Select <TResult>(Expression <Func <T, TResult> > func)
        {
            string fieldName = new ExpressionTool()
            {
                Parameter = Parameter, Provider = _dao.Provider, TargetType = typeof(T)
            }.GetSqlByExpression(func).ToString();

            fieldName = _dao.Provider.EscapeIdentifier(fieldName);
            var mapping = TableMapper.GetTableMapping(_dao, typeof(T));
            var command = _dao.Provider.CreateSelectAllCommand(mapping, null);

            return(_dao.QueryScalarList <TResult>(command.CommandText.Replace("*", fieldName) + WhereString + OrderByStr, Parameter));
        }
Exemple #2
0
        private void AppendOrderStr(Expression func, string exp)
        {
            string descFieldName = new ExpressionTool()
            {
                Parameter = Parameter, Provider = _dao.Provider, TargetType = typeof(T)
            }.GetSqlByExpression(func).ToString();

            descFieldName = _dao.Provider.EscapeIdentifier(descFieldName);
            if (OrderByStr.IsNullOrEmpty())
            {
                OrderByStr = " ORDER BY ";
            }
            else if (OrderByStr.IndexOf("ORDER BY", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                OrderByStr += ",";
            }

            OrderByStr += descFieldName + " " + exp;
        }