Example #1
0
        public static void FillClassFields <T>(Dictionary <string, object> row, T outObj)
        {
            string colName = "";

            foreach (var kvp in row)
            {
                try
                {
                    colName = kvp.Key;
                    var fld = typeof(T).GetField(colName);
                    if (fld != null)
                    {
                        fld.SetValue(fld, kvp.Value);
                    }
                    else
                    {
                        var prop = typeof(T).GetProperty(colName);
                        if (prop != null)
                        {
                            if (!(kvp.Value is DBNull))
                            {
                                object valueUse = kvp.Value;
                                CMySQLConv.SetSpecificType(prop, kvp.Value, ref valueUse);
                                prop.SetValue(outObj, valueUse, null);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw  e;
                }
            }
        }
Example #2
0
        public void GenOneTableSchema(string tableName)
        {
            _tablesSchemas[tableName] = new List <string>();

            _tablesSchemasCols[tableName] = new List <CColumn>();


            string sql = "select * from " + tableName;

            lock (_dbLocker)
            {
                MySqlCommand    command = new MySqlCommand(sql, _connection);
                MySqlDataReader rd      = command.ExecuteReader();

                var schemaTable = rd.GetSchemaTable();

                foreach (DataRow row in schemaTable.Rows)
                {
                    foreach (DataColumn col in schemaTable.Columns)
                    {
                        if (col.ToString() == "ColumnName")
                        {
                            _tablesSchemas[tableName].Add(row[col].ToString());
                            _tablesSchemasCols[tableName].Add(new CColumn {
                                Name = row[col].ToString()
                            });
                        }
                        else if (col.ToString() == "DataType")
                        {
                            var  currCol = _tablesSchemasCols[tableName].Last();
                            bool b;
                            currCol.TypeDonNet = CUtil.GetPropertyString(row[col], "Name");
                            currCol.TypeSQL    = CMySQLConv.ToMySQLType(currCol.TypeDonNet, out b);
                        }
                    }
                }


                rd.Close();
            }
        }