/// <summary> /// Creates a function delegate that returns a <see cref="IStructuralEquatable"/> instance, /// representing the key values for the given <paramref name="type"/>. /// </summary> /// <param name="type">The <see cref="Type"/> for which to build the delegate.</param> /// <param name="dataRecord">The <see cref="IDataRecord"/> containing the target fields/columns.</param> /// <returns>A function delegate used to retrieve key values for the given <paramref name="type"/>.</returns> public Func <IDataRecord, IStructuralEquatable> CreateKeyDelegate(Type type, IDataRecord dataRecord) { IEnumerable <PropertyMappingInfo> ordinals = propertyMapper.Execute(type, dataRecord); var keyOrdinal = GetValidPropertyMappingWithTheSmallestOrdinal(ordinals); if (keyOrdinal == null) { return(null); } Type keyType = typeof(Tuple <>).MakeGenericType(keyOrdinal.Property.PropertyType); var keyMethod = keyInstanceEmitter.CreateMethod(keyType); return(dr => keyMethod(dr, new[] { keyOrdinal.Ordinal })); }
/// <summary> /// Executes the selector and returns the ordinals required to read the columns from the data record. /// </summary> /// <param name="type">The <see cref="Type"/> for which to return the ordinals.</param> /// <param name="dataRecord">The <see cref="IDataRecord"/> that represents the available fields/columns.</param> /// <returns>A list of ordinals.</returns> public int[] Execute(Type type, IDataRecord dataRecord) { return(propertyMapper.Execute(type, dataRecord).Select(pm => pm.Ordinal).ToArray()); }
/// <summary> /// Returns a list of <see cref="PropertyMappingInfo"/> instances that /// represents the mapping between the fields from the <paramref name="dataRecord"/> and /// the <paramref name="type"/> properties. /// </summary> /// <param name="type">The <see cref="Type"/> containing the target properties.</param> /// <param name="dataRecord">The <see cref="IDataRecord"/> that contains the target fields/columns.</param> /// <returns>A list of <see cref="PropertyMappingInfo"/> instances where each instance represents a match /// between a field/column name and a property name.</returns> public IEnumerable <PropertyMappingInfo> Execute(Type type, IDataRecord dataRecord) { return(cache.GetOrAdd(type, t => propertyMapper.Execute(type, dataRecord))); }
private bool HasAtLeastOneMappedProperty(Type type, IDataRecord dataRecord) { return(propertyMapper.Execute(type, dataRecord).Any(pm => pm.Ordinal > -1)); }