public ITypeMetadata Resolve(TypeHandle th) { if (!m_MetadataCache.TryGetValue(th, out ITypeMetadata metadata)) { metadata = m_MetadataCache[th] = m_Factory.Create(th); } return(metadata); }
public void BuildParameters(IDbCommand cmd, object param) { foreach (var accessor in metadataFactory.Create(param.GetType()).GetParameterAccessors()) { var parameter = cmd.CreateParameter(); parameter.ParameterName = accessor.Name; var value = accessor.GetValue(param) ?? DBNull.Value; parameter.DbType = dbTypeMap.LookupDbType(accessor.Type); parameter.Value = value; cmd.Parameters.Add(parameter); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="factory"></param> /// <param name="reader"></param> /// <param name="converter"></param> /// <returns></returns> public IEnumerable <T> Handle <T>(Func <T> factory, IDataReader reader, ObjectConverter converter) { using (reader) { var metadata = metadataFactory.Create(typeof(T)); var columns = new string[reader.FieldCount]; var accessors = new IAccessor[reader.FieldCount]; for (var i = 0; i < columns.Length; i++) { var name = reader.GetName(i); columns[i] = name; accessors[i] = metadata.GetMapAccessor(name); } while (reader.Read()) { var entity = factory(); for (var i = 0; i < columns.Length; i++) { var accessor = accessors[i]; if (accessor == null) { continue; } if (reader.IsDBNull(i)) { accessor.SetValue(entity, accessor.Type.GetDefaultValue()); } else { var value = reader[columns[i]]; if (accessor.Type != value.GetType()) { value = converter.Convert(value, accessor.Type); } accessor.SetValue(entity, value); } } yield return(entity); } } }
public ITypeMetadata Create(TypeHandle th) { ITypeMetadata metadata = m_DecoratedFactory.Create(th); return(new CachedTypeMetadata(metadata)); }