public User GetUser(int id) { using (this.connection = this.factory.CreateConnection()) { this.connection.ConnectionString = this.connectionString; this.connection.Open(); this.command = this.connection.CreateCommand(); this.command.CommandText = "SELECT * FROM " + User.Mapper.TableName + " WHERE ID = " + id; User result = null; DbDataReader reader = command.ExecuteReader(); if (reader.HasRows && reader.Read()) { result = new User(); foreach (var item in typeof(User).GetProperties()) { MapTrio map = User.Mapper.PropertyMapTrios.Where(pmt => pmt.Property == item).FirstOrDefault(); // item.SetValue(result, Converter.ConvertFromDBValue(reader[map.TableFieldName])); item.SetValue(result, reader[map.TableFieldName]); //object obj = reader[map.TableFieldName]; //if (item.Name != "RegDate") // item.SetValue(result, reader[map.TableFieldName]); //else // result.RegDate = (DateTime)reader[map.TableFieldName]; } } return(result); } }
public static void Remap(string propName, string newTableFieldName) { MapTrio mapTrio = Mapper.PropertyMapTrios.Where(pmt => pmt.Property.Name == propName).FirstOrDefault(); try { mapTrio.TableFieldName = newTableFieldName; } catch (NullReferenceException ex) { Console.WriteLine(ex.Message); } }