/// <summary> /// Converts the <see cref="RecordSet"/> items to <see cref="Entity"/> instances. /// </summary> /// <param name="source">The <see cref="RecordSet"/> to process.</param> /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param> /// <returns>The sequence of <see cref="Entity"/> instances.</returns> public static IEnumerable <Entity> ToEntities(this RecordSet source, int primaryKeyIndex) { var session = ((EnumerationContext)source.Context).Session; var reader = session.Domain.RecordSetReader; foreach (var record in reader.Read(source, source.Header, session)) { var key = record.GetKey(primaryKeyIndex); if (key == null) { continue; } var tuple = record.GetTuple(primaryKeyIndex); if (tuple != null) { yield return(session.Handler.UpdateState(key, tuple).Entity); } else { yield return(session.Query.SingleOrDefault(key)); } } }
/// <summary> /// Converts the <see cref="RecordSet"/> items to <see cref="Entity"/> instances. /// </summary> /// <typeparam name="T">The type of <see cref="Entity"/> instances to get.</typeparam> /// <param name="source">The <see cref="RecordSet"/> to process.</param> /// <param name="primaryKeyIndex">Index of primary key within the <see cref="Record"/>.</param> /// <returns>The sequence of <see cref="Entity"/> instances.</returns> public static IEnumerable <T> ToEntities <T>(this RecordSet source, int primaryKeyIndex) where T : class, IEntity { return(ToEntities(source, primaryKeyIndex).Cast <T>()); }