示例#1
0
 //Get base class objects corresponding to a given IncludeBinding.
 private Func <TableEntityRow, object[]> Get_GetBaseObjects_Computation(IncludeBinding binding, MaterializationData data)
 {
     return(Get_GetBaseObjects_Computation(data, b => b.MatchesTarget(binding)));
 }
示例#2
0
        private Func <object, TableEntityRow, object> Get_GetOrCreateEntity_Computation(IncludeBinding includeBinding, MaterializationData data)
        {
            var getbaseObjects    = Get_GetBaseObjects_Computation(includeBinding, data);
            var entityConstructor = new EntityConstructor(entityContext, includeBinding.Type);

            return((projectedEntity, source) =>
            {
                if (projectedEntity == null)
                {
                    return null;
                }
                var tableObjects = new List <object>();
                tableObjects.Add(projectedEntity);
                tableObjects.AddRange(getbaseObjects(source));
                return entityConstructor.GetOrCreateEntity(tableObjects.ToArray());
            });
        }
示例#3
0
        private Action <object, TableEntityRow> Get_AttachIncludes_Computation(Type entityType, IncludeBinding includeBinding
                                                                               , MaterializationData data)
        {
            var includeBindings = data.ProjectedType.RelatedBindings
                                  .Where(b => b is IncludeBinding && b.TargetBinding == includeBinding).Cast <IncludeBinding>().ToList();
            var setIncludes = includeBindings.Select(b => Get_AttachIncludes_Computation(includeBinding.Type, b, data)).ToList();

            //The fieldNo is 1 more than the related-binding index; since the first field [0] is the main entity itself.
            var fieldNo = data.ProjectedType.RelatedBindings.IndexOf(includeBinding) + 1;

            var getOrCreateEntityOrCollection = Get_GetOrCreateEntityOrCollection_Computation(includeBinding, data);
            var memberInfo = (includeBinding.IncludeDirective.GetSelector().Body as MemberExpression).Member;

            //Handling Many-to-Many Map type separately
            if (entityContext._InternalServices.TypeTranslationUtil.GetMapping <IMapEntityMapping>(entityType) != null)
            {
                return((parent, source) =>
                {
                    //Setting the include directive in the intermediate object
                    (parent as IEntity)._getIntermediateEntity().IncludeDirectives.Add(includeBinding.IncludeDirective);

                    var valueInProjection = source.Values[fieldNo];
                    var memberValue = getOrCreateEntityOrCollection(valueInProjection, source);
                    memberInfo.SetValue(parent, memberValue);
                    setIncludes.ForEach(f => f(memberValue, source));
                });
            }

            //Not a Many-to-Many Collection
            else
            {
                var backingContainerGetter = entityContext._InternalServices.TypeTranslationUtil
                                             .MakeBackingContainerGetter(entityType, memberInfo);

                return((parent, source) =>
                {
                    //Setting the include directive in the intermediate object
                    (parent as IEntity)._getIntermediateEntity().IncludeDirectives.Add(includeBinding.IncludeDirective);

                    var valueInProjection = source.Values[fieldNo];
                    var intermediateContainerOnParent = backingContainerGetter((parent as IEntity)._getIntermediateEntity());
                    var memberValue = getOrCreateEntityOrCollection(valueInProjection, source);

                    if (null == memberValue)
                    {
                        return;
                    }

                    if (memberValue is IList)
                    {
                        foreach (var entity in (memberValue as IList))
                        {
                            intermediateContainerOnParent.MaterializationAddReference((entity as IEntity)._getIntermediateEntity());
                        }
                    }
                    else
                    {
                        intermediateContainerOnParent.MaterializationAddReference((memberValue as IEntity)._getIntermediateEntity());
                    }
                    var member = memberInfo.GetValue(parent);
                    setIncludes.ForEach(f => f(member, source));
                });
            }
        }
示例#4
0
        private Func <object, TableEntityRow, object> Get_GetOrCreateEntityOrCollection_Computation(IncludeBinding includeBinding, MaterializationData data)
        {
            if (entityContext._InternalServices.TypeTranslationUtil.IsEntityCollection(includeBinding.Type))
            {
                var unprojectedBinding = data.ProjectedType.UnprojectedBindings
                                         .Find(ub => (ub is UnprojectedCollectionBinding || ub is UnprojectedManyToManyBinding) && ub.TargetBinding == includeBinding);
                if (unprojectedBinding != null)
                {
                    if (unprojectedBinding is UnprojectedManyToManyBinding)
                    {
                        return(Get_GetUnprojectedCollections_Computation(unprojectedBinding, data.ManyToManyMaps));
                    }
                    else
                    {
                        return(Get_GetUnprojectedCollections_Computation(unprojectedBinding, data.InheritanceChains));
                    }
                }
                else
                {
                    var collItemType = TypesUtil.GetGenericArgumentForBaseType(includeBinding.Type, typeof(ICollection <>));
                    var collectionEntityConstructor = new EntityConstructor(entityContext, collItemType);

                    return((tableEntity, source) =>
                    {
                        var list = new List <object>();
                        foreach (var item in (tableEntity as IEnumerable))
                        {
                            list.Add(collectionEntityConstructor.GetOrCreateEntity(new object[] { item }));
                        }
                        return list;
                    });
                }
            }

            return(Get_GetOrCreateEntity_Computation(includeBinding, data));
        }