Пример #1
0
        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);
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
 public T CreateInstanceGraph <T>(Row row, ObjectRelation relation)
 {
     return(CreateInstanceGraph <T>(row, new[] { relation }));
 }
Пример #5
0
 private static void MapParentPropertyForChild(ObjectRelation relation, object child, object parent)
 {
     relation.ChildProperty.SetValue(child, parent, null);
 }
Пример #6
0
 public IList <T> CreateInstanceGraphs <T>(ResultSet resultSet, ObjectRelation parentChildRelation)
 {
     return(CreateInstanceGraphs <T>(resultSet, new[] { parentChildRelation }));
 }