private static void ReadEntity(Type entityType, IEntitySet target, IDataRecord reader, IServiceLocator factory) { var prototype = factory.Get(entityType) as IEntity; if (prototype == null) { throw new InvalidOperationException($"There is no IEntity implementing object setup for {entityType.Name}"); } if (!prototype.ReadPrimaryKey(reader)) { return; } var entity = target.Find(prototype.PrimaryKeyValue); if (entity == null) { prototype.ReadSelf(reader); target.Add(prototype); entity = prototype; } foreach (var referrenceProperty in entity.GetReferenceProperties()) { var list = entity.OpenProperty(referrenceProperty.Item1); var propReader = reader.GetDeeperReader(referrenceProperty.Item1); ReadEntity(referrenceProperty.Item2, list, propReader, factory); } }