private Dictionary <string, PropertyInfo> GetChildProperties() { Type type = GetType(); Dictionary <string, PropertyInfo> childProperties = new Dictionary <string, PropertyInfo>(); Logger.Trace($"Loading child properties for Entity '{type.Name}'."); foreach (PropertyInfo property in ReflectionUtil.GetProperties(this, typeof(ChildAttribute))) { Func <object> activator = ReflectionUtil.GetActivator(property.PropertyType); ChildAttribute childAttribute = (ChildAttribute)property.GetAttribute(typeof(ChildAttribute)); string tableName = childAttribute.TableName; compiledActivatorCache.CacheItem(property.PropertyType, activator); childProperties.Add(tableName, property); } childPropertyCache.CacheItem(type, childProperties); return(childProperties); }
public override dynamic Execute(SqlCommand command, SqlConnection connection, SqlTransaction?transaction = null) { if (transaction != null) { command.Transaction = transaction; } command.CommandType = CommandType.Text; foreach (Parameter parameter in GetParameters()) { command.Parameters.Add(parameter.ToSqlParameter()); } command.CommandText = ToString(); List <TBase> results = new List <TBase>(); EntityBeanMapping <TBase> mapping = GetMapping(); stopwatch.Start(); Func <object> activator = compiledActivatorCache.RetrieveItem(baseType); if (activator == null) { activator = ReflectionUtil.GetActivator(baseType); compiledActivatorCache.CacheItem(baseType, activator); } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { IEntityBean entityBean = (IEntityBean)activator(); foreach (PropertyInfo property in baseType.GetProperties()) { string columnName = mapping.PropertyMapping[property.Name].Name; property.SetValue(entityBean, Convert.ChangeType(reader[columnName], property.PropertyType)); } results.Add((TBase)entityBean); } } stopwatch.Stop(); Logger.Info(MethodBase.GetCurrentMethod(), $"Executed Read statement ({stopwatch.GetElapsedMicroseconds()}\u03BCs): {results.Count} result{(results.Count > 1 ? "s" : "")} retrieved"); return((List <TBase>)results); }