Example #1
0
 public TValue ReadInfo <T, TValue>(Expression <Func <T, TValue> > field, Expression <Func <T, bool> > condition) where T : class, new()
 {
     using (IExpressionCondition expression = db.GetExpressionCondition(condition))
     {
         string conditionSql = expression.ToCondition(out DynamicParameters parameters);
         string sql          = $"SELECT  { SchemaCache.GetColumnProperty(field).Name } FROM {typeof(T).GetTableName()} {conditionSql}  LIMIT 0,1;";
         object value        = db.ExecuteScalar(CommandType.Text, sql, parameters);
         if (value == null)
         {
             return(default);
Example #2
0
        /// <summary>
        /// 读取一个字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="field"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IEnumerable <TValue> ReadList <T, TValue>(Expression <Func <T, TValue> > field, Expression <Func <T, bool> > condition) where T : class, new()
        {
            string        fieldName = SchemaCache.GetColumnProperty(field).Name;
            List <TValue> list      = new List <TValue>();

            using (ExpressionCondition expression = db.GetExpressionCondition(condition))
            {
                string      conditionSql = expression.ToCondition(out DynamicParameters parameters);
                string      sql          = $"SELECT {fieldName} FROM [{typeof(T).GetTableName()}] {conditionSql}";
                IDataReader reader       = db.ReadData(CommandType.Text, sql, parameters);
                while (reader.Read())
                {
                    list.Add((TValue)reader[0]);
                }
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }
            return(list);
        }