Example #1
0
        private IEnumerable <EdmProperty> GenerateIndependentForeignKeyColumns(
            EntityType principalEntityType,
            EntityType dependentEntityType,
            AssociationSetMapping associationSetMapping,
            EndPropertyMapping associationEndMapping,
            EntityType dependentTable,
            bool isPrimaryKeyColumn,
            NavigationProperty principalNavigationProperty)
        {
            foreach (EdmProperty keyProperty in principalEntityType.KeyProperties())
            {
                string      columnName       = (principalNavigationProperty != null ? principalNavigationProperty.Name : principalEntityType.Name) + "_" + keyProperty.Name;
                EdmProperty foreignKeyColumn = this.MapTableColumn(keyProperty, columnName, false);
                dependentTable.AddColumn(foreignKeyColumn);
                if (isPrimaryKeyColumn)
                {
                    dependentTable.AddKeyMember((EdmMember)foreignKeyColumn);
                }
                foreignKeyColumn.Nullable = associationEndMapping.AssociationEnd.IsOptional() || associationEndMapping.AssociationEnd.IsRequired() && dependentEntityType.BaseType != null;
                foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None;
                yield return(foreignKeyColumn);

                associationEndMapping.AddPropertyMapping(new ScalarPropertyMapping(keyProperty, foreignKeyColumn));
                if (foreignKeyColumn.Nullable)
                {
                    associationSetMapping.AddCondition((ConditionPropertyMapping) new IsNullConditionMapping(foreignKeyColumn, false));
                }
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            var cond = new Condition(_associationSetMapping, null);

            cond.ColumnName.SetRefName(_tableColumn);
            _associationSetMapping.AddCondition(cond);

            ModelHelper.SetConditionPredicate(cond, _isNull, _conditionValue);

            XmlModelHelper.NormalizeAndResolve(cond);

            _created = cond;
        }
Example #3
0
        private IEnumerable <EdmProperty> GenerateIndependentForeignKeyColumns(
            EntityType principalEntityType,
            EntityType dependentEntityType,
            AssociationSetMapping associationSetMapping,
            EndPropertyMapping associationEndMapping,
            EntityType dependentTable,
            bool isPrimaryKeyColumn,
            NavigationProperty principalNavigationProperty)
        {
            DebugCheck.NotNull(principalEntityType);
            DebugCheck.NotNull(associationEndMapping);
            DebugCheck.NotNull(dependentTable);

            foreach (var property in principalEntityType.KeyProperties())
            {
                var columnName
                    = ((principalNavigationProperty != null)
                           ? principalNavigationProperty.Name
                           : principalEntityType.Name) + "_" + property.Name;

                var foreignKeyColumn
                    = MapTableColumn(property, columnName, false);

                dependentTable.AddColumn(foreignKeyColumn);

                if (isPrimaryKeyColumn)
                {
                    dependentTable.AddKeyMember(foreignKeyColumn);
                }

                foreignKeyColumn.Nullable
                    = associationEndMapping.AssociationEnd.IsOptional() ||
                      (associationEndMapping.AssociationEnd.IsRequired() &&
                       dependentEntityType.BaseType != null);

                foreignKeyColumn.StoreGeneratedPattern = StoreGeneratedPattern.None;

                yield return(foreignKeyColumn);

                associationEndMapping.AddPropertyMapping(new ScalarPropertyMapping(property, foreignKeyColumn));

                if (foreignKeyColumn.Nullable)
                {
                    associationSetMapping
                    .AddCondition(new IsNullConditionMapping(foreignKeyColumn, false));
                }
            }
        }
Example #4
0
        private static AssociationSetMapping BuildAssociationSetMapping(
            AssociationSet storeAssociationSet,
            EntityContainerMapping entityContainerMapping,
            SimpleMappingContext mappingContext)
        {
            Debug.Assert(storeAssociationSet != null, "storeAssociationSet != null");
            Debug.Assert(entityContainerMapping != null, "entityContainerMapping != null");
            Debug.Assert(mappingContext != null, "mappingContext != null");

            var modelAssociationSet = mappingContext[storeAssociationSet];

            if (modelAssociationSet.ElementType.IsForeignKey)
            {
                return(null);
            }

            var foreignKeyTableEnd    = GetAssociationSetEndForForeignKeyTable(storeAssociationSet);
            var associationSetMapping = new AssociationSetMapping(
                modelAssociationSet, foreignKeyTableEnd.EntitySet, entityContainerMapping);

            var count = storeAssociationSet.AssociationSetEnds.Count;

            if (count > 0)
            {
                associationSetMapping.SourceEndMapping = BuildEndPropertyMapping(
                    storeAssociationSet.AssociationSetEnds[0], mappingContext);
            }
            if (count > 1)
            {
                associationSetMapping.TargetEndMapping = BuildEndPropertyMapping(
                    storeAssociationSet.AssociationSetEnds[1], mappingContext);
            }

            var constraint = GetReferentialConstraint(storeAssociationSet);

            foreach (var foreignKeyColumn in constraint.ToProperties)
            {
                if (foreignKeyColumn.Nullable)
                {
                    associationSetMapping.AddCondition(
                        new IsNullConditionMapping(foreignKeyColumn, false));
                }
            }

            return(associationSetMapping);
        }