private void ConnectEntities(ObjectRelation relation, object child, object parent) { if (child == null || parent == null) { return; } if (relation.HasChildProperty) { MapParentPropertyForChild(relation, child, parent); } if (relation.HasParentProperty) { MapChildCollectionForParent(relation, child, parent); } }
private CreatedEntity CreateInstanceGraph(Type resultType, Row row, ObjectRelation relation, EntityCache entityCache, string primaryAlias) { var childType = relation.ChildType; var parentType = relation.ParentType; var child = CreateInstance(childType, row, entityCache, relation.ChildAlias); var parent = CreateInstance(parentType, row, entityCache, relation.ParentAlias); ConnectEntities(relation, child, parent); if (Matches(relation.ChildAlias, primaryAlias)) { return(CreatedEntity.Primary(child)); } if (Matches(relation.ParentAlias, primaryAlias)) { return(CreatedEntity.Primary(parent)); } return(resultType == childType?CreatedEntity.Ordinary(child) : CreatedEntity.Ordinary(parent)); }
private void MapChildCollectionForParent(ObjectRelation relation, object child, object parent) { var parentsChildCollection = (IList)relation.ParentProperty.GetValue(parent, null); if (parentsChildCollection == null) { var list = Reflector.CreateGenericList(child.GetType()); parentsChildCollection = list; relation.ParentProperty.SetValue(parent, list, null); } var comparer = GetEqualityComparer <object>(child.GetType()); var parentCollectionContainsChild = parentsChildCollection .OfType <object>() .Contains(child, comparer); if (!parentCollectionContainsChild) { parentsChildCollection.Add(child); } }
public T CreateInstanceGraph <T>(Row row, ObjectRelation relation) { return(CreateInstanceGraph <T>(row, new[] { relation })); }
private static void MapParentPropertyForChild(ObjectRelation relation, object child, object parent) { relation.ChildProperty.SetValue(child, parent, null); }
public IList <T> CreateInstanceGraphs <T>(ResultSet resultSet, ObjectRelation parentChildRelation) { return(CreateInstanceGraphs <T>(resultSet, new[] { parentChildRelation })); }