Пример #1
0
        /// <summary>
        /// 获取查询结果字段,绑定成对象
        /// </summary>
        /// <param name="dataReader"></param>
        /// <returns></returns>
        public static dynamic GetDataReader(this MySqlDataReader dataReader)
        {
            //dynamic dymodel = new System.Dynamic.ExpandoObject();
            List <string> fider = new List <string>();

            for (int i = 0; i < dataReader.FieldCount; i++)
            {
                fider.Add(dataReader.GetName(i));
            }

            ICollection <KeyValuePair <string, object> > fde = new System.Dynamic.ExpandoObject();//在运行时动态添加和删除其成员的对象。

            foreach (var item in fider)
            {
                var nm = new KeyValuePair <string, object>(item, dataReader[item]);
                if (!fde.Contains(nm))
                {
                    fde.Add(new KeyValuePair <string, object>(item, dataReader[item]));
                }
            }
            dynamic dymodel = fde;

            return(dymodel);
        }