Ejemplo n.º 1
0
        private void AddRelatedMember(string parentGuid, string childGuid, bool overwrite = false)
        {
            try
            {
                CFAggregation parent = Db.XmlModels.Where(x => x.MappedGuid == parentGuid).FirstOrDefault() as CFAggregation;
                CFItem        child  = Db.XmlModels.Where(x => x.MappedGuid == childGuid).FirstOrDefault() as CFItem;
                if (!overwrite)
                {
                    parent.AddRelated(child);
                }
                else
                {
                    //remove all child members first before adding new one
                    foreach (var c in parent.RelatedMembers)
                    {
                        CFItem removeRel = Db.XmlModels.Where(x => x.Id == c.Id).FirstOrDefault() as CFItem;
                        parent.RemoveRelated(removeRel);
                    }

                    //add new one
                    parent.AddRelated(child);
                }

                Db.Entry(parent).State = System.Data.Entity.EntityState.Modified;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <CFAggregation> Related(
            string id,
            out int total,
            string query     = "*:*",
            int page         = 1,
            int itemsPerPage = 10)
        {
            CFAggregation aggregation = Db.Aggregations.AsNoTracking().Where(x => id == x.MappedGuid).FirstOrDefault();
            List <string> mappedGuids = aggregation.RelatedMembers.Select(x => x.MappedGuid).ToList();

            string newQuery = query;

            if (mappedGuids.Count > 0)
            {
                string relatedIds = String.Join(" ", mappedGuids);
                if (newQuery.Length > 0)
                {
                    newQuery += " AND ";
                }
                newQuery += "id:(" + relatedIds + ")";
            }
            else
            {
                newQuery = "";
            }

            return(Index(out total, newQuery, page, itemsPerPage));
        }
Ejemplo n.º 3
0
        //public IQueryable<EntityType> GetEntityTypes()
        //{
        //    return Db.EntityTypes;
        //}

        //public IQueryable<EntityType> GetEntityTypes(EntityType.eTarget target)
        //{
        //    // return Db.EntityTypes.Where(et => et.TargetType == target);
        //     return Db.EntityTypes.Where(et => et.TargetTypes.Contains(target.ToString())); //Mr Jan 15 2018

        //}

        public void DisassociateFromAggregations(CFAggregation aggregation)
        {
            // Remove all parent aggregations
            {
                CFAggregation[] parents = aggregation.ParentMembers.ToArray();
                foreach (CFAggregation parent in parents)
                {
                    parent.RemoveChild(aggregation);
                    Db.Entry(parent).State = EntityState.Modified;
                }
            }

            // Remove all child aggregations
            {
                CFAggregation[] children = aggregation.ChildMembers.ToArray();
                foreach (CFAggregation child in children)
                {
                    aggregation.RemoveChild(child);
                    Db.Entry(child).State = EntityState.Modified;
                }
            }

            // Remove all child relationships
            {
                CFItem[] children = aggregation.RelatedMembers.ToArray();
                foreach (CFItem child in children)
                {
                    aggregation.RemoveRelated(child);
                    Db.Entry(child).State = EntityState.Modified;
                }
            }
        }
Ejemplo n.º 4
0
        protected AccessMode GetAggregationPermissions(string userGuid, CFAggregation entity)
        {
            if (IsAdmin(userGuid))
            {
                return(AccessMode.All);
            }

            AccessMode            modes        = AccessMode.None;
            List <string>         userGroups   = userListService.GetEntityGroupForUser(userGuid).Select(ul => ul.Id.ToString()).ToList();
            IList <CFAggregation> visitedNodes = new List <CFAggregation>();
            Queue <CFAggregation> entityQueue  = new Queue <CFAggregation>();

            IList <string> accessableGuids = new List <string>(userGroups);

            accessableGuids.Add(userGuid);

            entityQueue.Enqueue(entity);

            while (entityQueue.Count > 0)
            {
                CFAggregation currentEntity = entityQueue.Dequeue();
                visitedNodes.Add(currentEntity);

                // Check if we have any new permissions
                foreach (CFAccessGroup accessGroup in currentEntity.AccessGroups)
                {
                    foreach (Guid guid in accessGroup.AccessGuids)
                    {
                        string guidString = guid.ToString();
                        if (accessableGuids.Contains(guidString))
                        {
                            accessableGuids.Remove(guidString);
                            modes |= accessGroup.AccessDefinition.AccessModes;
                        }
                    }
                }

                // Move up the tree
                if (!currentEntity.BlockInheritance && modes < AccessMode.All)
                {
                    if (currentEntity.ParentMembers.Count > 0)
                    {
                        foreach (CFAggregation parent in currentEntity.ParentMembers)
                        {
                            if (!visitedNodes.Contains(parent))
                            {
                                entityQueue.Enqueue(parent);
                            }
                        }
                    }
                    else
                    {
                        modes |= GetDefaultPermissions();
                    }
                }
            }

            return(modes);
        }
 private void SetModifiedChildMembers(CFAggregation aggregation)
 {
     aggregation.ChildMembers.Each <CFAggregation>((i, x) =>
     {
         Db.Entry(x).State = System.Data.Entity.EntityState.Modified;
         SetModifiedChildMembers(x);
     });
 }
Ejemplo n.º 6
0
        public CFAggregationIndexViewModel(CFAggregation aggregation)
        {
            Name       = aggregation.Name;
            Id         = aggregation.Id;
            MappedGuid = aggregation.MappedGuid;
            EntityType = aggregation.EntityType.Name;
            string modelType = aggregation.Data.Attribute("model-type").Value;

            Label = AggregationService.GetModelTypeLabel(modelType);
        }
Ejemplo n.º 7
0
        public void SetHierarchyModified(CFAggregation aggregation)
        {
            Action <CFAggregation> setChildModified = (x) =>
            {
                Db.Entry(x).State = System.Data.Entity.EntityState.Modified;
            };

            //VisitHierarchy(aggregation, setChildModified);
            aggregation.VisitHierarchy(setChildModified);
        }
Ejemplo n.º 8
0
        private int ReIndexBucket(IEnumerable <int> bucket, string taskId)
        {
            int result = 0;

            using (CatfishDbContext db = new CatfishDbContext())
            {
                var SolrOperations = CommonServiceLocator.ServiceLocator.Current.GetInstance <SolrNet.ISolrOperations <Dictionary <string, object> > >();

                foreach (int aggregationId in bucket)
                {
                    CFAggregation aggregation = db.Aggregations.Find(aggregationId);
                    aggregation.RecalculateInheritedPermissions();
                    aggregation.Serialize();

                    if (aggregation.MappedGuid != aggregation.Guid)
                    {
                        aggregation.MappedGuid      = aggregation.Guid;
                        db.Entry(aggregation).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        // No need to update the entire model.
                        SolrOperations.Add(aggregation.ToSolrDictionary());
                    }

                    ++result;

                    try
                    {
                        ReIndexState.TaskProcessedCount[taskId] = result;
                    }
                    catch (KeyNotFoundException ex)
                    {
                        ReIndexState.TaskProcessedCount.Add(taskId, result);
                    }
                }

                try
                {
                    SolrOperations.Commit();
                    db.SaveChanges();
                }catch (Exception ex)
                {
                    ReIndexState.Errors.Add(string.Format("Error occured while saving data on task {2}: {0}\n{1}", ex.Message, ex.StackTrace, taskId));
                    result = 0;
                }
            }

            return(result);
        }
Ejemplo n.º 9
0
        public JsonResult UpdateRelatedItems(EntityContentViewModel vm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Model validation failed");
                }

                if (vm.Id == 0)
                {
                    throw new Exception("Parent model ID mnot specified");
                }

                CFAggregation model = Db.XmlModels.Where(x => x.Id == vm.Id).FirstOrDefault() as CFAggregation;
                if (model == null)
                {
                    throw new Exception("Specified parent entity of type Aggregation not found");
                }

                //Associating children
                foreach (var c in vm.ChildEntityList)
                {
                    CFItem child = Db.XmlModels.Where(x => x.Id == c.Id).FirstOrDefault() as CFItem;
                    if (child == null)
                    {
                        throw new Exception("Id=" + c.Id + ": Specified related item not found");
                    }

                    model.ChildRelations.Add(child);
                }

                //Removing deleted children
                foreach (var c in vm.RemovalPendingChildEntities)
                {
                    CFItem child = Db.XmlModels.Where(x => x.Id == c.Id).FirstOrDefault() as CFItem;
                    model.ChildRelations.Remove(child);
                }

                Db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                Db.SaveChanges(User.Identity);
                vm.Status = KoBaseViewModel.eStatus.Success;
                return(Json(vm));
            }
            catch (Exception ex)
            {
                return(Json(vm.Error("UpdateRelatedItems Error: " + ex.Message)));
            }
        }
        public ContentResult GetParents(AggregationRelationParameters parameters)
        {
            // XXX Fixme, change from getting children to get parents
            SecurityService.CreateAccessContext();

            if (String.IsNullOrEmpty(parameters.Query))
            {
                parameters.Query = "*:*";
            }

            CFAggregationAssociationsViewModel response = new CFAggregationAssociationsViewModel
            {
                Page         = parameters.Page,
                TotalItems   = 1,
                ItemsPerPage = 1,
                TotalPages   = 1
            };


            int total;

            //string mappedGuid =
            CFAggregation aggregation = AggregationService.GetAggregation(parameters.id);
            string        mappedGuid  = aggregation.MappedGuid;

            AggregationService.Detach(aggregation);
            response.Data = AggregationService.Parents(
                mappedGuid,
                out total,
                parameters.Query,
                response.Page,
                parameters.ItemsPerPage).Select(x => new CFAggregationIndexViewModel(x));

            response.TotalItems   = total;
            response.ItemsPerPage = parameters.ItemsPerPage;
            response.TotalPages   = (int)Math.Ceiling((double)response.TotalItems / response.ItemsPerPage);

            string responseString = JsonConvert.SerializeObject(response,
                                                                Formatting.None
                                                                );

            return(Content(responseString, "application/json"));
        }
        public JsonResult RemoveRelated(int id, int[] objectIds)
        {
            SecurityService.CreateAccessContext();
            CFAggregation aggregation = AggregationService.GetAggregation(id);

            foreach (CFItem related in ItemService.GetItems(objectIds))
            {
                if (related != null)
                {
                    aggregation.RemoveRelated(related);
                    Db.Entry(related).State = System.Data.Entity.EntityState.Modified;
                }
            }
            Db.Entry(aggregation).State = System.Data.Entity.EntityState.Modified;


            Db.SaveChanges(User.Identity);
            return(Json(""));
        }
        public JsonResult RemoveChildren(int id, int[] objectIds)
        {
            SecurityService.CreateAccessContext();
            CFAggregation aggregation = AggregationService.GetAggregation(id);

            foreach (CFAggregation child in AggregationService.GetAggregations(objectIds))
            {
                if (child != null)
                {
                    aggregation.RemoveChild(child);
                    //Db.Entry(child).State = System.Data.Entity.EntityState.Modified;
                    AggregationService.SetHierarchyModified(child);
                }
            }
            Db.Entry(aggregation).State = System.Data.Entity.EntityState.Modified;
            AggregationService.SetHierarchyModified(aggregation);

            Db.SaveChanges(User.Identity);
            return(Json(""));
        }
        public ContentResult GetRelated([System.Web.Http.FromUri] AggregationRelationParameters parameters)
        {
            SecurityService.CreateAccessContext();

            if (String.IsNullOrEmpty(parameters.Query))
            {
                parameters.Query = "*:*";
            }

            CFAggregationAssociationsViewModel response = new CFAggregationAssociationsViewModel
            {
                Page         = parameters.Page,
                TotalItems   = 1,
                ItemsPerPage = 1,
                TotalPages   = 1
            };


            // XXX Fix me
            int total;

            //string mappedGuid =
            CFAggregation test = AggregationService.GetAggregation(parameters.id);

            response.Data = AggregationService.Related(
                test.MappedGuid,
                out total,
                parameters.Query,
                response.Page,
                parameters.ItemsPerPage).Select(x => new CFAggregationIndexViewModel(x));

            response.TotalItems   = total;
            response.ItemsPerPage = parameters.ItemsPerPage;
            response.TotalPages   = (int)Math.Ceiling((double)response.TotalItems / response.ItemsPerPage);

            string responseString = JsonConvert.SerializeObject(response,
                                                                Formatting.None
                                                                );

            return(Content(responseString, "application/json"));
        }
        public JsonResult AddParents(int id, int[] objectIds)
        {
            SecurityService.CreateAccessContext();
            CFAggregation aggregation = AggregationService.GetAggregation(id);

            foreach (CFAggregation parent in AggregationService.GetAggregations(objectIds))
            {
                if (parent != null)
                {
                    parent.AddChild(aggregation);
                    //Db.Entry(parent).State = System.Data.Entity.EntityState.Modified;
                    if (parent != aggregation)
                    {
                        AggregationService.SetHierarchyModified(parent);
                    }
                }
            }
            Db.Entry(aggregation).State = System.Data.Entity.EntityState.Modified;
            Db.SaveChanges(User.Identity);
            return(Json("Ok"));
        }
Ejemplo n.º 15
0
        public void Import(Ingestion ingestion)
        {
#if DEBUG
            Console.Error.WriteLine("Starting ingestion of Ingestion object.");
#endif

            //create new GUID and new EntityType-Id
            Dictionary <string, string> GuidMap = new Dictionary <string, string>();
            Dictionary <int, int>       IdMap   = new Dictionary <int, int>();


            foreach (CFMetadataSet ms in ingestion.MetadataSets)
            {
                string oldId   = ms.Guid;
                string newGuid = NewGuid();
                var    meta    = ms;
                if (ingestion.Overwrite)
                {
                    //use whatever GUID in the file
                    //check to make sure the GUID in not existing in the Db, if it's replace the one in the database
                    GuidMap.Add(oldId, oldId); //if overwrite is true use existing GUID
                }
                else
                {
                    GuidMap.Add(oldId, newGuid);
                }
                //GuidMap = buildMapGuid(ingestion.Overwrite, oldId);
                ms.Guid       = GuidMap[oldId];
                ms.MappedGuid = GuidMap[oldId];

                ms.Serialize();
                //meta.Serialize();
                if (ingestion.Overwrite)
                {
                    //check if the metadataset with this guid is existed in the database
                    //if yes, replace the one in th edatabase with this one from the file
                    CFMetadataSet metadataSet = Db.MetadataSets.Where(m => m.MappedGuid == ms.Guid).FirstOrDefault();
                    if (metadataSet != null)
                    {
                        metadataSet = ms;
                        Db.Entry(metadataSet).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        Db.MetadataSets.Add(ms);
                    }
                }
                else
                {
                    try
                    {
                        Db.MetadataSets.Add(ms);
                    }catch (ProviderIncompatibleException ex)
                    {
                        Console.Error.WriteLine("Current Connection String: " + Db.Database.Connection.ConnectionString);

                        throw ex;
                    }
                }
            }

            Db.SaveChanges();
            //add entityType
            foreach (CFEntityType et in ingestion.EntityTypes)
            {
                int oldId = et.Id;

                //I think below is not necessary since the DeserialiseEntytyType mtehod already grabbing the right metadataset

                List <CFMetadataSet> newSets = new List <CFMetadataSet>();
                foreach (CFMetadataSet set in et.MetadataSets)
                {
                    string mGuid = set.Guid;
                    if (GuidMap.ContainsKey(mGuid))
                    {
                        mGuid = GuidMap[mGuid];
                    }

                    CFMetadataSet dbSet = Db.MetadataSets.Where(s => s.MappedGuid == mGuid).FirstOrDefault();
                    newSets.Add(dbSet);
                }
                et.MetadataSets.Clear();
                et.MetadataSets = newSets;

                foreach (CFEntityTypeAttributeMapping mapping in et.AttributeMappings)
                {
                    string mGuid = mapping.MetadataSet.Guid;
                    if (GuidMap.ContainsKey(mGuid))
                    {
                        mGuid = GuidMap[mGuid];
                    }
                    mapping.MetadataSet = Db.MetadataSets.Where(m => m.MappedGuid == mGuid).FirstOrDefault();
                }

                CFEntityType newEt = null;
                if (ingestion.Overwrite)
                {
                    CFEntityType oldEt = Db.EntityTypes.Where(e => e.Name == et.Name).FirstOrDefault();
                    if (oldEt != null)
                    {
                        //modified it --replace with current value
                        oldEt = et;
                        Db.Entry(oldEt).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        newEt = Db.EntityTypes.Add(et);
                    }
                }
                else
                {
                    newEt = Db.EntityTypes.Add(et);
                }
                Db.SaveChanges();
                IdMap.Add(oldId, newEt.Id);
            }

            //add aggregations
            GuidMap.Clear();
            int completed = 0;
            int failed    = 0;
            IDictionary <Type, Func <IngestionService, CFXmlModel, CFAggregation> > createAggrigationCache = new Dictionary <Type, Func <IngestionService, CFXmlModel, CFAggregation> >();
            Func <CFXmlModel, CFAggregation> getNewAggregation = agg =>
            {
                Type t = agg.GetType();

                try
                {
                    return(createAggrigationCache[t](this, agg));
                }
                catch (KeyNotFoundException ex)
                {
                    MethodInfo method    = this.GetType().GetMethod("CreateAggregation");
                    MethodInfo genMethod = method.MakeGenericMethod(t);
                    Func <IngestionService, CFXmlModel, CFAggregation> func = (Func <IngestionService, CFXmlModel, CFAggregation>)Delegate.CreateDelegate(typeof(Func <IngestionService, CFXmlModel, CFAggregation>), genMethod);
                    createAggrigationCache.Add(t, func);
                    Console.WriteLine("Exception : {0}", ex.Message);
                    return(func(this, agg));
                }
            };

            ingestion.Aggregations.ForEach((agg) => {
                Regex guidRegex = new Regex(@"(guid)=[""']?((?:.(?![""']?\s + (?:\S +)=|[> ""']))+.)[""']?");
                string oldId    = guidRegex.Match(agg.Content).Groups[2].Value;
                string newGuid  = NewGuid();

                //saving the aggregation object
                if (ingestion.Overwrite)
                {
                    //use whatever GUID in the file
                    //check to make sure the GUID in not existing in the Db, if it's replace the one in the database
                    GuidMap.Add(oldId, oldId); //if overwrite is true use existing GUID

                    CFAggregation _aggregation = Db.XmlModels.Where(a => a.MappedGuid == oldId).FirstOrDefault() as CFAggregation;
                    if (_aggregation != null)
                    {
                        _aggregation = (CFAggregation)agg;
                        Db.Entry(_aggregation).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        var _agg = getNewAggregation(agg);
                        Db.Entities.Add(_agg);
                    }
                }
                else
                {
                    agg.Guid       = newGuid;
                    agg.MappedGuid = newGuid;

                    GuidMap.Add(oldId, newGuid);

                    var _agg = getNewAggregation(agg);

                    try
                    {
                        Db.Entities.Add(_agg);
                    }catch (Exception ex)
                    {
#if DEBUG
                        Console.Error.WriteLine("{0} Error reading aggrigation: {1}", ex.Message, _agg.Name);
#endif
                        return(false);
                    }
                }

                return(true);
            }, (successCount, failCount) =>
            {
                completed += successCount;
                failed    += failCount;

#if DEBUG
                Console.Error.WriteLine("{0} Completed, {1} Failed", completed, failed);
#endif

                Db.SaveChanges();
                return(true);
            });

            Db.SaveChanges();
            foreach (var rel in ingestion.Relationships)
            {
                string pGuid = rel.ParentRef;
                if (GuidMap.ContainsKey(pGuid))
                {
                    pGuid = GuidMap[pGuid];
                }

                string cGuid = rel.ChildRef;
                if (GuidMap.ContainsKey(cGuid))
                {
                    cGuid = GuidMap[cGuid];
                }

                rel.ParentRef = pGuid;
                rel.ChildRef  = cGuid;
                if (rel.IsMember)
                {
                    AddMember(rel.ParentRef, rel.ChildRef);
                }

                if (rel.IsRelated)
                {
                    //save it in Aggregation has related
                    AddRelatedMember(rel.ParentRef, rel.ChildRef);
                }
            }
        }
Ejemplo n.º 16
0
        public void Import(Ingestion ingestion)
        {
            //create new GUID and new EntityType-Id
            Dictionary <string, string> GuidMap = new Dictionary <string, string>();
            Dictionary <int, int>       IdMap   = new Dictionary <int, int>();


            foreach (CFMetadataSet ms in ingestion.MetadataSets)
            {
                string oldId   = ms.Guid;
                string newGuid = NewGuid();
                var    meta    = ms;
                if (ingestion.Overwrite)
                {
                    //use whatever GUID in the file
                    //check to make sure the GUID in not existing in the Db, if it's replace the one in the database
                    GuidMap.Add(oldId, oldId); //if overwrite is true use existing GUID
                }
                else
                {
                    GuidMap.Add(oldId, newGuid);
                }
                //GuidMap = buildMapGuid(ingestion.Overwrite, oldId);
                ms.Guid       = GuidMap[oldId];
                ms.MappedGuid = GuidMap[oldId];

                ms.Serialize();
                //meta.Serialize();
                if (ingestion.Overwrite)
                {
                    //check if the metadataset with this guid is existed in the database
                    //if yes, replace the one in th edatabase with this one from the file
                    CFMetadataSet metadataSet = Db.MetadataSets.Where(m => m.MappedGuid == ms.Guid).FirstOrDefault();
                    if (metadataSet != null)
                    {
                        metadataSet = ms;
                        Db.Entry(metadataSet).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        Db.MetadataSets.Add(ms);
                    }
                }
                else
                {
                    Db.MetadataSets.Add(ms);
                }
            }

            Db.SaveChanges();
            //add entityType
            foreach (CFEntityType et in ingestion.EntityTypes)
            {
                int oldId = et.Id;

                //I think below is not necessary since the DeserialiseEntytyType mtehod already grabbing the right metadataset

                List <CFMetadataSet> newSets = new List <CFMetadataSet>();
                foreach (CFMetadataSet set in et.MetadataSets)
                {
                    string mGuid = set.Guid;
                    if (GuidMap.ContainsKey(mGuid))
                    {
                        mGuid = GuidMap[mGuid];
                    }

                    CFMetadataSet dbSet = Db.MetadataSets.Where(s => s.MappedGuid == mGuid).FirstOrDefault();
                    newSets.Add(dbSet);
                }
                et.MetadataSets.Clear();
                et.MetadataSets = newSets;

                foreach (CFEntityTypeAttributeMapping mapping in et.AttributeMappings)
                {
                    string mGuid = mapping.MetadataSet.Guid;
                    if (GuidMap.ContainsKey(mGuid))
                    {
                        mGuid = GuidMap[mGuid];
                    }
                    mapping.MetadataSet = Db.MetadataSets.Where(m => m.MappedGuid == mGuid).FirstOrDefault();
                }

                CFEntityType newEt = null;
                if (ingestion.Overwrite)
                {
                    CFEntityType oldEt = Db.EntityTypes.Where(e => e.Name == et.Name).FirstOrDefault();
                    if (oldEt != null)
                    {
                        //modified it --replace with current value
                        oldEt = et;
                        Db.Entry(oldEt).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        newEt = Db.EntityTypes.Add(et);
                    }
                }
                else
                {
                    newEt = Db.EntityTypes.Add(et);
                }
                Db.SaveChanges();
                IdMap.Add(oldId, newEt.Id);
            }

            //add aggregations
            GuidMap.Clear();
            foreach (var agg in ingestion.Aggregations)
            {
                string oldId   = agg.Guid;
                string newGuid = NewGuid();

                if (ingestion.Overwrite)
                {
                    //use whatever GUID in the file
                    //check to make sure the GUID in not existing in the Db, if it's replace the one in the database
                    GuidMap.Add(oldId, oldId); //if overwrite is true use existing GUID
                }
                else
                {
                    agg.Guid       = newGuid;
                    agg.MappedGuid = newGuid;

                    GuidMap.Add(oldId, newGuid);
                }

                //saving the aggregation object
                if (ingestion.Overwrite)
                {
                    CFAggregation _aggregation = Db.XmlModels.Where(a => a.MappedGuid == newGuid).FirstOrDefault() as CFAggregation;
                    if (_aggregation != null)
                    {
                        _aggregation = (CFAggregation)agg;
                        Db.Entry(_aggregation).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        Type       t         = agg.GetType();
                        MethodInfo method    = this.GetType().GetMethod("CreateAggregation");
                        MethodInfo genMethod = method.MakeGenericMethod(t);
                        var        _agg      = (CFAggregation)genMethod.Invoke(this, new object[] { agg });
                        Db.Entities.Add(_agg);
                    }
                }
                else
                {
                    Type       t         = agg.GetType();
                    MethodInfo method    = this.GetType().GetMethod("CreateAggregation");
                    MethodInfo genMethod = method.MakeGenericMethod(t);
                    var        _agg      = (CFAggregation)genMethod.Invoke(this, new object[] { agg });
                    Db.Entities.Add(_agg);
                }
            }
            Db.SaveChanges();
            foreach (var rel in ingestion.Relationships)
            {
                string pGuid = rel.ParentRef;
                if (GuidMap.ContainsKey(pGuid))
                {
                    pGuid = GuidMap[pGuid];
                }

                string cGuid = rel.ChildRef;
                if (GuidMap.ContainsKey(cGuid))
                {
                    cGuid = GuidMap[cGuid];
                }

                rel.ParentRef = pGuid;
                rel.ChildRef  = cGuid;
                if (rel.IsMember)
                {
                    AddMember(rel.ParentRef, rel.ChildRef);
                }

                if (rel.IsRelated)
                {
                    //save it in Aggregation has related
                    AddRelatedMember(rel.ParentRef, rel.ChildRef);
                }
            }
        }