private static void Associate(CrmDbContext context, ContentMap map, EntityReference target, Relationship relationship, EntityReferenceCollection relatedEntities)
        {
            target.ThrowOnNull("target");
            relationship.ThrowOnNull("relationship");
            relatedEntities.ThrowOnNull("relatedEntities");

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Target: LogicalName={0}, Id={1}", EntityNamePrivacy.GetEntityName(target.LogicalName), target.Id));
            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Relationship: SchemaName={0}, PrimaryEntityRole={1}", relationship.SchemaName, relationship.PrimaryEntityRole));

            foreach (var entity in relatedEntities)
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Related: LogicalName={0}, Id={1}", EntityNamePrivacy.GetEntityName(entity.LogicalName), entity.Id));
            }

            // validate that the relationships do in fact exist by querying for the intersects

            var entities = map.Using(ContentMapLockType.Read, () => RetrieveIntersectEntities(context, map, target, relationship, relatedEntities));

            if (entities != null)
            {
                // add intersect entities to the content map

                map.Using(ContentMapLockType.Write, () => map.AddRange(entities));

                foreach (var added in entities)
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Added: LogicalName={0}, Id={1}", EntityNamePrivacy.GetEntityName(added.LogicalName), added.Id));
                }
            }
        }
        protected virtual void BuildContentMap(ContentMap map, IEnumerable <Entity> entities)
        {
            var sw = Stopwatch.StartNew();

            map.AddRange(entities);

            ApplyBaseSolutionVersionToWebsite(map);

            sw.Stop();

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Duration: {0} ms", sw.ElapsedMilliseconds));
        }