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); }
public void InstantiateChildProperties() { Type type = GetType(); Dictionary <string, PropertyInfo> childProperties = childPropertyCache.RetrieveItem(type) ?? GetChildProperties(); foreach (PropertyInfo property in childProperties.Values) { Func <object> activator = compiledActivatorCache.RetrieveItem(property.PropertyType) ?? GetActivator(property); object instance = activator(); property.SetValue(this, instance); } }