コード例 #1
0
        private void CopyRelationshipRecords <T>(IRepository <T> repository, EntityMetadataRecord existing, EntityMetadataRecord building) where T : IRelationshipRecord, new()
        {
            var records = repository.Table
                          .Where(x => (x.Relationship.PrimaryEntity == existing && x.Relationship.RelatedEntity == existing) ||
                                 (x.Relationship.PrimaryEntity == existing && x.Relationship.RelatedEntity.ContentItemVersionRecord.Latest) ||
                                 (x.Relationship.RelatedEntity == existing && x.Relationship.PrimaryEntity.ContentItemVersionRecord.Latest))
                          .ToList();

            foreach (var record in records)
            {
                var relationshipRecord = GetNewRelationshipRecord(record.Relationship, existing, building);
                var newRecord          = new T();
                repository.Copy(record, newRecord);
                newRecord.Relationship = relationshipRecord;
                repository.Create(newRecord);
            }
        }
コード例 #2
0
        private RelationshipRecord GetNewRelationshipRecord(RelationshipRecord record, EntityMetadataRecord existing, EntityMetadataRecord building)
        {
            var newRecord = new RelationshipRecord();

            _relationshipRepository.Copy(record, newRecord);
            if (newRecord.PrimaryEntity == existing)
            {
                newRecord.PrimaryEntity = building;
            }
            if (newRecord.RelatedEntity == existing)
            {
                newRecord.RelatedEntity = building;
            }
            _relationshipRepository.Create(newRecord);
            return(newRecord);
        }