private IEnumerable <IRelatedEnd> GetAllRelatedEnds(Object item, EndToEndEnum endToEndEnum)
        {
            var itemEntry = Context.AsObjectContext().ObjectStateManager.GetObjectStateEntry(item);

            List <IRelatedEnd> relEndsResult = new List <IRelatedEnd>();

            IEnumerable <IRelatedEnd> relEnds =
                itemEntry.RelationshipManager
                .GetAllRelatedEnds();

            if (relEnds.Count() > 0)
            {
                foreach (IRelatedEnd relEnd in relEnds)
                {
                    var typeofrel = relEnd.GetType();

                    if (endToEndEnum == EndToEndEnum.OneToOne && relEnd is System.Data.Entity.Core.Objects.DataClasses.EntityReference)
                    {
                        relEndsResult.Add(relEnd);
                    }
                    else if (endToEndEnum == EndToEndEnum.OneToMany && !(relEnd is System.Data.Entity.Core.Objects.DataClasses.EntityReference))
                    {
                        //here big assumption....
                        relEndsResult.Add(relEnd);
                    }
                }
            }

            return(relEndsResult);
        }
        protected void LoadRelations(DbContext dbContext, object item, EndToEndEnum endToEndType)
        {
            IEnumerable <IRelatedEnd> relEnds = GetAllRelatedEnds(item, endToEndType);

            foreach (IRelatedEnd relEnd in relEnds)
            {
                if (!relEnd.IsLoaded)
                {
                    relEnd.Load();
                }

                foreach (var loeadedItem in relEnd)
                {
                    LoadRelations(dbContext, loeadedItem, EndToEndEnum.OneToOne);
                }
            }
        }
        private IEnumerable<IRelatedEnd> GetAllRelatedEnds(Object item, EndToEndEnum endToEndEnum)
        {
            var itemEntry = Context.AsObjectContext().ObjectStateManager.GetObjectStateEntry(item);

            List<IRelatedEnd> relEndsResult = new List<IRelatedEnd>();

            IEnumerable<IRelatedEnd> relEnds =
               itemEntry.RelationshipManager
                    .GetAllRelatedEnds();

            if (relEnds.Count() > 0)
            {
                foreach (IRelatedEnd relEnd in relEnds)
                {
                    var typeofrel = relEnd.GetType();

                    if (endToEndEnum == EndToEndEnum.OneToOne && relEnd is System.Data.Entity.Core.Objects.DataClasses.EntityReference)
                    {
                        relEndsResult.Add(relEnd);
                    }
                    else if (endToEndEnum == EndToEndEnum.OneToMany && !(relEnd is System.Data.Entity.Core.Objects.DataClasses.EntityReference))
                    {
                        //here big assumption....
                        relEndsResult.Add(relEnd);
                    }
                }
            }

            return relEndsResult;
        }
        protected void LoadRelations(DbContext dbContext, object item, EndToEndEnum endToEndType)
        {
            IEnumerable<IRelatedEnd> relEnds = GetAllRelatedEnds(item, endToEndType);

            foreach (IRelatedEnd relEnd in relEnds)
            {
                if (!relEnd.IsLoaded)
                {
                    relEnd.Load();
                }

                foreach (var loeadedItem in relEnd)
                {
                    LoadRelations(dbContext, loeadedItem, EndToEndEnum.OneToOne);
                }
            }
        }