private static AssociationSet ConvertToAssociationSet(
            EntityContainerRelationshipSet relationshipSet,
            DbProviderManifest providerManifest,
            Converter.ConversionCache convertedItemCache,
            EntityContainer container,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            AssociationType associationType = (AssociationType)Converter.LoadSchemaElement((System.Data.Entity.Core.SchemaObjectModel.SchemaType)relationshipSet.Relationship, providerManifest, convertedItemCache, newGlobalItems);
            AssociationSet  parentSet       = new AssociationSet(relationshipSet.Name, associationType);

            foreach (EntityContainerRelationshipSetEnd end in relationshipSet.Ends)
            {
                EntityType           entityType        = (EntityType)Converter.LoadSchemaElement((System.Data.Entity.Core.SchemaObjectModel.SchemaType)end.EntitySet.EntityType, providerManifest, convertedItemCache, newGlobalItems);
                AssociationEndMember member            = (AssociationEndMember)associationType.Members[end.Name];
                AssociationSetEnd    associationSetEnd = new AssociationSetEnd(Converter.GetEntitySet(end.EntitySet, container), parentSet, member);
                Converter.AddOtherContent((SchemaElement)end, (MetadataItem)associationSetEnd);
                parentSet.AddAssociationSetEnd(associationSetEnd);
                if (end.Documentation != null)
                {
                    associationSetEnd.Documentation = Converter.ConvertToDocumentation(end.Documentation);
                }
            }
            if (relationshipSet.Documentation != null)
            {
                parentSet.Documentation = Converter.ConvertToDocumentation(relationshipSet.Documentation);
            }
            Converter.AddOtherContent((SchemaElement)relationshipSet, (MetadataItem)parentSet);
            return(parentSet);
        }
 public AssociationSetEndDetails(
     AssociationSetEnd associationSetEnd, RelationshipMultiplicity multiplicity,
     OperationAction deleteBehavior)
 {
     AssociationSetEnd = associationSetEnd;
     Multiplicity = multiplicity;
     DeleteBehavior = deleteBehavior;
 }
        private void LogRelationEntityEnd(EntityKey mainKey, EntityKey relatedKey, System.Data.Entity.Core.Metadata.Edm.AssociationSetEnd relatedAssociationEnd, EntityState relationStatus, AuditingWidget widget)
        {
            var ctx          = (widget.TrackedContext as IObjectContextAdapter).ObjectContext;
            var relatedEntry = ctx.ObjectStateManager.GetObjectStateEntry(mainKey);

            if (relatedEntry.State != EntityState.Detached && relatedEntry.State != EntityState.Unchanged)
            {
                var relatedAuditLog = widget.TrackedEntities[relatedEntry];
                LogRelatedEntryDetails(relatedAssociationEnd.EntitySet.Name, relatedKey, relatedAuditLog, widget, relationStatus == EntityState.Added);
            }
        }
        /// <summary>
        /// Initializes a new ModificationFunctionMemberPath instance.
        /// </summary>
        /// <param name="members">Gets the members in the path from the leaf (the member being bound)
        /// to the root of the structure.</param>
        /// <param name="associationSet">Gets the association set to which we are navigating 
        /// via this member. If the value is null, this is not a navigation member path.</param>
        public ModificationFunctionMemberPath(IEnumerable<EdmMember> members, AssociationSet associationSet)
        {
            Check.NotNull(members, "members");

            _members = new ReadOnlyCollection<EdmMember>(new List<EdmMember>(members));

            if (null != associationSet)
            {
                Debug.Assert(2 == Members.Count, "Association bindings must always consist of the end and the key");

                // find the association set end
                _associationSetEnd = associationSet.AssociationSetEnds[Members[1].Name];
            }
        }
 protected virtual void Visit(AssociationSetEnd associationSetEnd)
 {
     Visit(associationSetEnd.CorrespondingAssociationEndMember);
     Visit(associationSetEnd.EntitySet);
     Visit(associationSetEnd.ParentAssociationSet);
 }
Exemple #6
0
 internal RoleBoolean(AssociationSetEnd end)
 {
     m_metadataItem = end;
 }
        private static DbRelatedEntityRef RelatedEntityRefFromAssociationSetEnd(
            EntityType constructedEntityType, DbNewInstanceExpression entityConstructor, AssociationSetEnd principalSetEnd,
            ReferentialConstraint fkConstraint)
        {
            var principalEntityType = (EntityType)TypeHelpers.GetEdmType<RefType>(fkConstraint.FromRole.TypeUsage).ElementType;
            IList<DbExpression> principalKeyValues = null;

            // Create Entity Property/DbExpression value pairs from the entity constructor DbExpression,
            // then join these with the principal/dependent property pairs from the FK constraint
            // to produce principal property name/DbExpression value pairs from which to create the principal ref.
            //
            // Ideally the code would be as below, but anonymous types break asmmeta:
            //var keyPropAndValue =
            //    from pv in constructedEntityType.Properties.Select((p, idx) => new { DependentProperty = p, Value = entityConstructor.Arguments[idx] })
            //    join ft in fkConstraint.FromProperties.Select((fp, idx) => new { PrincipalProperty = fp, DependentProperty = fkConstraint.ToProperties[idx] })
            //    on pv.DependentProperty equals ft.DependentProperty
            //    select new { PrincipalProperty = ft.PrincipalProperty.Name, Value = pv.Value };
            //
            var keyPropAndValue =
                from pv in constructedEntityType.Properties.Select((p, idx) => Tuple.Create(p, entityConstructor.Arguments[idx]))
                // new { DependentProperty = p, Value = entityConstructor.Arguments[idx] })
                join ft in fkConstraint.FromProperties.Select((fp, idx) => Tuple.Create(fp, fkConstraint.ToProperties[idx]))
                    //new { PrincipalProperty = fp, DependentProperty = fkConstraint.ToProperties[idx] })
                    on pv.Item1 equals ft.Item2
                //pv.DependentProperty equals ft.DependentProperty
                select Tuple.Create(ft.Item1.Name, pv.Item2); // new { PrincipalProperty = ft.PrincipalProperty.Name, Value = pv.Value };

            // If there is only a single property in the principal's key, then there is no ordering concern.
            // Otherwise, create a dictionary of principal key property name to DbExpression value so that
            // when used as the arguments to the ref expression, the dependent property values - used here
            // as principal key property values - are in the correct order, which is the same order as the
            // key members themselves.
            //
            if (fkConstraint.FromProperties.Count == 1)
            {
                var singleKeyNameAndValue = keyPropAndValue.Single();
                Debug.Assert(singleKeyNameAndValue.Item1 == fkConstraint.FromProperties[0].Name, "Unexpected single key property name");
                principalKeyValues = new[] { singleKeyNameAndValue.Item2 };
            }
            else
            {
                var keyValueMap = keyPropAndValue.ToDictionary(pav => pav.Item1, pav => pav.Item2, StringComparer.Ordinal);
                principalKeyValues = principalEntityType.KeyMemberNames.Select(memberName => keyValueMap[memberName]).ToList();
            }

            // Create the ref to the principal entity based on the (now correctly ordered) key value expressions.
            //
            var principalRef = principalSetEnd.EntitySet.CreateRef(principalEntityType, principalKeyValues);
            var result = DbExpressionBuilder.CreateRelatedEntityRef(fkConstraint.ToRole, fkConstraint.FromRole, principalRef);

            return result;
        }
        /// <summary>
        /// Converts an association set from SOM to metadata
        /// </summary>
        /// <param name="relationshipSet">The SOM element to process</param>
        /// <param name="providerManifest">The provider manifest to be used for conversion</param>
        /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param>
        /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param>
        /// <param name="container"></param>
        /// <returns>The association set object resulting from the convert</returns>
        private static AssociationSet ConvertToAssociationSet(
            Som.EntityContainerRelationshipSet relationshipSet,
            DbProviderManifest providerManifest,
            ConversionCache convertedItemCache,
            EntityContainer container,
            Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems)
        {
            Debug.Assert(relationshipSet.Relationship.RelationshipKind == RelationshipKind.Association);

            var associationType = (AssociationType)LoadSchemaElement(
                (Som.SchemaType)relationshipSet.Relationship,
                providerManifest,
                convertedItemCache,
                newGlobalItems);

            var associationSet = new AssociationSet(relationshipSet.Name, associationType);

            foreach (var end in relationshipSet.Ends)
            {
                //-- need the EntityType for the end
                var endEntityType = (EntityType)LoadSchemaElement(
                    end.EntitySet.EntityType,
                    providerManifest,
                    convertedItemCache,
                    newGlobalItems);
                //-- need to get the end member
                var endMember = (AssociationEndMember)associationType.Members[end.Name];
                //-- create the end
                var associationSetEnd = new AssociationSetEnd(
                    GetEntitySet(end.EntitySet, container),
                    associationSet,
                    endMember);

                AddOtherContent(end, associationSetEnd);
                associationSet.AddAssociationSetEnd(associationSetEnd);

                // Extract optional Documentation from the end element
                if (end.Documentation != null)
                {
                    associationSetEnd.Documentation = ConvertToDocumentation(end.Documentation);
                }
            }

            // Extract the optional Documentation
            if (relationshipSet.Documentation != null)
            {
                associationSet.Documentation = ConvertToDocumentation(relationshipSet.Documentation);
            }
            AddOtherContent(relationshipSet, associationSet);

            return associationSet;
        }
Exemple #9
0
 // <summary>
 // Adds the given end to the collection of ends
 // </summary>
 internal void AddAssociationSetEnd(AssociationSetEnd associationSetEnd)
 {
     AssociationSetEnds.Source.Add(associationSetEnd);
 }
        private static EdmProperty GetAssociatedFkColumn(AssociationSetEnd storeEnd, EdmProperty storeKeyProperty)
        {
            Debug.Assert(storeEnd != null, "storeEnd != null");
            Debug.Assert(storeKeyProperty != null, "storeKeyProperty != null");

            var constraint = GetReferentialConstraint(storeEnd.ParentAssociationSet);
            if (storeEnd.Name == constraint.FromRole.Name)
            {
                for (var i = 0; i < constraint.FromProperties.Count; i++)
                {
                    if (constraint.FromProperties[i] == storeKeyProperty)
                    {
                        return constraint.ToProperties[i];
                    }
                }
            }

            return storeKeyProperty;
        }
        private static EndPropertyMapping BuildEndPropertyMapping(
            AssociationSetEnd storeSetEnd,
            SimpleMappingContext mappingContext)
        {
            Debug.Assert(storeSetEnd != null, "storeSetEnd != null");
            Debug.Assert(mappingContext != null, "mappingContext != null");

            var endPropertyMapping =
                new EndPropertyMapping
                    {
                        AssociationEnd = mappingContext[storeSetEnd].CorrespondingAssociationEndMember
                    };

            foreach (EdmProperty storeKeyMember in storeSetEnd.EntitySet.ElementType.KeyMembers)
            {
                var modelKeyMember = mappingContext[storeKeyMember];
                var storeFkTableMember = GetAssociatedFkColumn(storeSetEnd, storeKeyMember);

                endPropertyMapping.AddPropertyMapping(
                    new ScalarPropertyMapping(modelKeyMember, storeFkTableMember));
            }

            return endPropertyMapping;
        }
        protected override void Visit(AssociationSetEnd associationSetEnd)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(associationSetEnd, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(associationSetEnd, index);

            #region Inner data visit

            AddObjectContentToHashBuilder(associationSetEnd.Identity);
            // Name is covered by Identity

            base.Visit(associationSetEnd);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
 // <summary>
 // Adds the given end to the collection of ends
 // </summary>
 internal void AddAssociationSetEnd(AssociationSetEnd associationSetEnd)
 {
     AssociationSetEnds.Source.Add(associationSetEnd);
 }
 public void AddMapping(AssociationSetEnd storeAssociationSetEnd, AssociationSetEnd conceptualAssociationSetEnd)
 {
     _associationSetEndMappings.Add(storeAssociationSetEnd, conceptualAssociationSetEnd);
 }
 public AssociationSetEnd this[AssociationSetEnd storeAssociationSetEnd]
 {
     get { return _associationSetEndMappings[storeAssociationSetEnd]; }
 }