public void Can_get_flattened_properties_for_nested_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));
            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var columnMappingBuilders = mappingFragment.FlattenedProperties.ToList();

            Assert.Equal(2, columnMappingBuilders.Count());
            Assert.True(columnMappingBuilder1.PropertyPath.SequenceEqual(columnMappingBuilders.First().PropertyPath));
            Assert.True(columnMappingBuilder2.PropertyPath.SequenceEqual(columnMappingBuilders.Last().PropertyPath));
        }
예제 #2
0
        public void AddEntityTypeMappingFragment(
            EntitySet entitySet, EntityType entityType, MappingFragment fragment)
        {
            Debug.Assert(fragment.Table == Table);

            _entityTypes.Add(entitySet, entityType);

            var defaultDiscriminatorColumn = fragment.GetDefaultDiscriminator();

            foreach (var cm in fragment.ColumnMappings)
            {
                var columnMapping = FindOrCreateColumnMapping(cm.ColumnProperty);
                columnMapping.AddMapping(
                    entityType,
                    cm.PropertyPath,
                    fragment.ColumnConditions.Where(cc => cc.Column == cm.ColumnProperty),
                    defaultDiscriminatorColumn == cm.ColumnProperty);
            }

            // Add any column conditions that aren't mapped to properties
            foreach (
                var cc in
                    fragment.ColumnConditions.Where(cc => fragment.ColumnMappings.All(pm => pm.ColumnProperty != cc.Column)))
            {
                var columnMapping = FindOrCreateColumnMapping(cc.Column);
                columnMapping.AddMapping(entityType, null, new[] { cc }, defaultDiscriminatorColumn == cc.Column);
            }
        }
예제 #3
0
        public void Can_get_flattened_properties_for_nested_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var columnMappingBuilders = mappingFragment.FlattenedProperties.ToList();

            Assert.Equal(2, columnMappingBuilders.Count());
            Assert.True(columnMappingBuilder1.PropertyPath.SequenceEqual(columnMappingBuilders.First().PropertyPath));
            Assert.True(columnMappingBuilder2.PropertyPath.SequenceEqual(columnMappingBuilders.Last().PropertyPath));
        }
예제 #4
0
        /// <summary>
        /// Adds a mapping fragment.
        /// </summary>
        /// <param name="fragment">The mapping fragment to be added.</param>
        public void AddFragment(MappingFragment fragment)
        {
            Check.NotNull(fragment, "fragment");
            ThrowIfReadOnly();

            _fragments.Add(fragment);
        }
예제 #5
0
        /// <summary>
        /// Removes a mapping fragment.
        /// </summary>
        /// <param name="fragment">The mapping fragment to be removed.</param>
        public void RemoveFragment(MappingFragment fragment)
        {
            Check.NotNull(fragment, "fragment");
            ThrowIfReadOnly();

            _fragments.Remove(fragment);
        }
예제 #6
0
        public void WriteMappingFragment_should_write_store_entity_set_name()
        {
            var fixture = new Fixture();

            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", null, null, entityType);
            var entityContainer = new EntityContainer("EC", DataSpace.SSpace);

            entityContainer.AddEntitySetBase(entitySet);

            var storageEntitySetMapping
                = new EntitySetMapping(
                    entitySet,
                    new EntityContainerMapping(entityContainer));

            TypeMapping typeMapping = new EntityTypeMapping(storageEntitySetMapping);

            var mappingFragment = new MappingFragment(entitySet, typeMapping, false);

            fixture.Writer.WriteMappingFragmentElement(mappingFragment);

            Assert.Equal(
                @"<MappingFragment StoreEntitySet=""ES"" />",
                fixture.ToString());
        }
        public void Can_add_scalar_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));
            var property = new EdmProperty("P");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());

            var scalarPropertyMapping = (ScalarPropertyMapping)mappingFragment.PropertyMappings.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.Column);
            Assert.Same(property, scalarPropertyMapping.Property);
        }
        public void Can_add_and_remove_column_conditions()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnConditions);

            var conditionPropertyMapping
                = new ValueConditionMapping(new EdmProperty("C", TypeUsage.Create(new PrimitiveType {
                DataSpace = DataSpace.SSpace
            })), 42);

            mappingFragment.AddConditionProperty(conditionPropertyMapping);

            Assert.Same(conditionPropertyMapping, mappingFragment.ColumnConditions.Single());

            mappingFragment.RemoveConditionProperty(conditionPropertyMapping);

            Assert.Empty(mappingFragment.ColumnConditions);
        }
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.PropertyMappings);

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.PropertyMappings.Single());

            mappingFragment.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(mappingFragment.PropertyMappings);
        }
예제 #10
0
 private static IEnumerable <ColumnMappingBuilder> GetFlattenedProperties(
     IEnumerable <PropertyMapping> propertyMappings,
     List <EdmProperty> propertyPath)
 {
     foreach (PropertyMapping propertyMapping in propertyMappings)
     {
         propertyPath.Add(propertyMapping.Property);
         ComplexPropertyMapping storageComplexPropertyMapping = propertyMapping as ComplexPropertyMapping;
         if (storageComplexPropertyMapping != null)
         {
             foreach (ColumnMappingBuilder flattenedProperty in MappingFragment.GetFlattenedProperties((IEnumerable <PropertyMapping>)storageComplexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>().PropertyMappings, propertyPath))
             {
                 yield return(flattenedProperty);
             }
         }
         else
         {
             ScalarPropertyMapping storageScalarPropertyMapping = propertyMapping as ScalarPropertyMapping;
             if (storageScalarPropertyMapping != null)
             {
                 yield return(new ColumnMappingBuilder(storageScalarPropertyMapping.Column, (IList <EdmProperty>)propertyPath.ToList <EdmProperty>()));
             }
         }
         propertyPath.Remove(propertyMapping.Property);
     }
 }
        public void Can_remove_complex_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));
            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());
            Assert.NotEmpty(mappingFragment.PropertyMappings);

            mappingFragment.RemoveColumnMapping(columnMappingBuilder);

            Assert.Empty(mappingFragment.ColumnMappings);
            Assert.Empty(mappingFragment.PropertyMappings);
        }
예제 #12
0
 protected virtual void Visit(MappingFragment mappingFragment)
 {
     foreach (PropertyMapping propertyMapping in this.GetSequence <PropertyMapping>((IEnumerable <PropertyMapping>)mappingFragment.AllProperties, (Func <PropertyMapping, string>)(it => BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(it))))
     {
         this.Visit(propertyMapping);
     }
     this.Visit((EntitySetBase)mappingFragment.TableSet);
 }
예제 #13
0
        protected virtual void Visit(MappingFragment mappingFragment)
        {
            foreach (var property in GetSequence(mappingFragment.AllProperties, it => IdentityHelper.GetIdentity(it)))
            {
                Visit(property);
            }

            Visit((EntitySetBase)mappingFragment.TableSet);
        }
        public static void GetIdentity_of_StorageMappingFragment_returns_expected_value()
        {
            var entityType        = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet         = new EntitySet("ES", "S", "T", null, entityType);
            var entityTypeMapping = new EntityTypeMapping(null);

            entityTypeMapping.AddType(entityType);
            var mappingFragment = new MappingFragment(entitySet, entityTypeMapping, false);

            Assert.Equal(entitySet.Identity,
                         BaseMetadataMappingVisitor.IdentityHelper.GetIdentity(mappingFragment));
        }
        protected override void Visit(MappingFragment mappingFragment)
        {
            int instanceIndex;

            if (!this.AddObjectToSeenListAndHashBuilder((object)mappingFragment, out instanceIndex))
            {
                return;
            }
            this.AddObjectStartDumpToHashBuilder((object)mappingFragment, instanceIndex);
            this.AddV2ObjectContentToHashBuilder((object)mappingFragment.IsSQueryDistinct, this.m_MappingVersion);
            base.Visit(mappingFragment);
            this.AddObjectEndDumpToHashBuilder();
        }
예제 #16
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var entitySet = new EntitySet();
            var entityTypeMapping
                = new EntityTypeMapping(
                      new EntitySetMapping(
                          entitySet,
                          new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace))));
            var fragment = new MappingFragment(entitySet, entityTypeMapping, false);

            entityTypeMapping.AddFragment(fragment);

            Assert.False(fragment.IsReadOnly);
            entityTypeMapping.SetReadOnly();
            Assert.True(fragment.IsReadOnly);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            var associationSet = new AssociationSet("AS", associationType);
            var associationSetMapping
                = new AssociationSetMapping(
                    associationSet,
                    new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));
            var associationTypeMapping = new AssociationTypeMapping(associationSetMapping);
            var fragment = new MappingFragment(new EntitySet(), associationTypeMapping, false);
            associationTypeMapping.MappingFragment = fragment;

            Assert.False(fragment.IsReadOnly);
            associationTypeMapping.SetReadOnly();
            Assert.True(fragment.IsReadOnly);
        }
        public void Can_get_table()
        {
            var table = new EntityType("E", "N", DataSpace.CSpace);

            var tableSet = new EntitySet("ES", null, null, null, table);

            var mappingFragment
                = new MappingFragment(
                      tableSet,
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Same(table, mappingFragment.Table);
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            var associationSet  = new AssociationSet("AS", associationType);
            var associationSetMapping
                = new AssociationSetMapping(
                      associationSet,
                      new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));
            var associationTypeMapping = new AssociationTypeMapping(associationSetMapping);
            var fragment = new MappingFragment(new EntitySet(), associationTypeMapping, false);

            associationTypeMapping.MappingFragment = fragment;

            Assert.False(fragment.IsReadOnly);
            associationTypeMapping.SetReadOnly();
            Assert.True(fragment.IsReadOnly);
        }
        public void MappingFragments_returns_mapping_fragment_if_set()
        {
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);

            var setMapping
                = new AssociationSetMapping(
                      new AssociationSet("AS", associationType),
                      new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));

            var associationTypeMapping = new AssociationTypeMapping(setMapping);
            var fragment = new MappingFragment(new EntitySet(), associationTypeMapping, false);

            associationTypeMapping.MappingFragment = fragment;

            Assert.Equal(new[] { fragment }, associationTypeMapping.MappingFragments);
            Assert.Same(fragment, associationTypeMapping.MappingFragment);
        }
예제 #21
0
        public void Cannot_add_mapping_fragment_when_read_only()
        {
            var setMapping
                = new EntitySetMapping(
                      new EntitySet(),
                      new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));
            var typeMapping
                = new EntityTypeMapping(setMapping);

            typeMapping.SetReadOnly();

            var mappingFragment = new MappingFragment(new EntitySet(), typeMapping, false);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => typeMapping.AddFragment(mappingFragment)).Message);
        }
예제 #22
0
        public void Cannot_add_mapping_fragment_when_read_only()
        {
            var setMapping
                = new EntitySetMapping(
                    new EntitySet(),
                    new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));
            var typeMapping
                = new EntityTypeMapping(setMapping);

            typeMapping.SetReadOnly();

            var mappingFragment = new MappingFragment(new EntitySet(), typeMapping, false);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => typeMapping.AddFragment(mappingFragment)).Message);
        }
        public void Cannot_add_condition_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            mappingFragment.SetReadOnly();

            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mappingFragment.AddCondition(conditionMapping)).Message);
        }
        internal void Configure(
            DbDatabaseMapping databaseMapping, MappingFragment fragment, EntityType entityType)
        {
            DebugCheck.NotNull(fragment);

            var edmPropertyPath = EntityMappingConfiguration.PropertyPathToEdmPropertyPath(PropertyPath, entityType);

            if (edmPropertyPath.Count() > 1)
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            var column
                = fragment.ColumnMappings
                          .Where(pm => pm.PropertyPath.SequenceEqual(edmPropertyPath.Single()))
                          .Select(pm => pm.ColumnProperty)
                          .SingleOrDefault();

            if (column == null
                || !fragment.Table.Properties.Contains(column))
            {
                throw Error.InvalidNotNullCondition(PropertyPath.ToString(), entityType.Name);
            }

            if (ValueConditionConfiguration.AnyBaseTypeToTableWithoutColumnCondition(
                databaseMapping, entityType, fragment.Table, column))
            {
                column.Nullable = true;
            }

            // Make the property required
            var newConfiguration = new Properties.Primitive.PrimitivePropertyConfiguration
                {
                    IsNullable = false,
                    OverridableConfigurationParts =
                        OverridableConfigurationParts.OverridableInSSpace
                };

            newConfiguration.Configure(edmPropertyPath.Single().Last());

            fragment.AddNullabilityCondition(column, isNull: false);
        }
        public void Can_get_and_set_table_set()
        {
            var tableSet = new EntitySet();

            var mappingFragment
                = new MappingFragment(
                      tableSet,
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Same(tableSet, mappingFragment.TableSet);

            tableSet = new EntitySet();

            mappingFragment.TableSet = tableSet;

            Assert.Same(tableSet, mappingFragment.TableSet);
        }
        public void GetComplexPropertyMappings_should_return_all_complex_property_mappings_for_type()
        {
            var databaseMapping = new DbDatabaseMapping()
                .Initialize(new EdmModel(DataSpace.CSpace), new EdmModel(DataSpace.SSpace));
            var entitySet = new EntitySet
                                {
                                    Name = "ES"
                                };
            var entitySetMapping = databaseMapping.AddEntitySetMapping(entitySet);
            var entityTypeMapping = new EntityTypeMapping(null);
            entitySetMapping.AddTypeMapping(entityTypeMapping);
            var entityTypeMappingFragment = new MappingFragment(entitySet, entityTypeMapping, false);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);
            var complexType = new ComplexType("C");
            var propertyMapping1
                = new ColumnMappingBuilder(
                    new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })),
                    new[]
                        {
                            EdmProperty.CreateComplex("P1", complexType),
                            EdmProperty.CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String))
                        });
            var type = typeof(object);

            complexType.GetMetadataProperties().SetClrType(type);

            entityTypeMappingFragment.AddColumnMapping(propertyMapping1);

            var propertyMapping2
                = new ColumnMappingBuilder(
                    new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })),
                    new List<EdmProperty>
                        {
                            EdmProperty.CreateComplex("P3", complexType),
                            EdmProperty.CreatePrimitive(
                                "P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                        });
            entityTypeMappingFragment.AddColumnMapping(propertyMapping2);

            Assert.Equal(2, databaseMapping.GetComplexPropertyMappings(typeof(object)).Count());
        }
        public void Generate(EntityType entityType, DbDatabaseMapping databaseMapping)
        {
            DebugCheck.NotNull(entityType);
            DebugCheck.NotNull(databaseMapping);

            var entitySet = databaseMapping.Model.GetEntitySet(entityType);

            var entitySetMapping
                = databaseMapping.GetEntitySetMapping(entitySet)
                  ?? databaseMapping.AddEntitySetMapping(entitySet);

            var entityTypeMapping =
                entitySetMapping.EntityTypeMappings.FirstOrDefault(
                    m => m.EntityTypes.Contains(entitySet.ElementType))
                ?? entitySetMapping.EntityTypeMappings.FirstOrDefault();

            var table
                = entityTypeMapping != null
                      ? entityTypeMapping.MappingFragments.First().Table
                      : databaseMapping.Database.AddTable(entityType.GetRootType().Name);

            entityTypeMapping = new EntityTypeMapping(null);

            var entityTypeMappingFragment
                = new MappingFragment(databaseMapping.Database.GetEntitySet(table), entityTypeMapping, false);

            entityTypeMapping.AddType(entityType);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);
            entityTypeMapping.SetClrType(entityType.GetClrType());

            entitySetMapping.AddTypeMapping(entityTypeMapping);

            new PropertyMappingGenerator(_providerManifest)
                .Generate(
                    entityType,
                    entityType.Properties,
                    entitySetMapping,
                    entityTypeMappingFragment,
                    new List<EdmProperty>(),
                    false);
        }
        public void Cannot_add_invalid_column_mapping_builder()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Equal(
                "columnMappingBuilder",
                Assert.Throws <ArgumentNullException>(
                    () => mappingFragment.AddColumnMapping(null)).ParamName);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws <ArgumentException>(
                    () => mappingFragment.AddColumnMapping(
                        new ColumnMappingBuilder(new EdmProperty("S"), new List <EdmProperty>()))).Message);
        }
        protected override void Visit(MappingFragment mappingFragment)
        {
            int index;

            if (!AddObjectToSeenListAndHashBuilder(mappingFragment, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(mappingFragment, index);

            #region Inner data visit

            AddV2ObjectContentToHashBuilder(mappingFragment.IsSQueryDistinct, m_MappingVersion);

            base.Visit(mappingFragment);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
예제 #30
0
        private static void RemoveColumnMapping(
            StructuralTypeMapping structuralTypeMapping,
            IEnumerable <EdmProperty> propertyPath)
        {
            PropertyMapping propertyMapping = structuralTypeMapping.PropertyMappings.Single <PropertyMapping>((Func <PropertyMapping, bool>)(pm => object.ReferenceEquals((object)pm.Property, (object)propertyPath.First <EdmProperty>())));

            if (propertyMapping is ScalarPropertyMapping)
            {
                structuralTypeMapping.RemovePropertyMapping(propertyMapping);
            }
            else
            {
                ComplexPropertyMapping complexPropertyMapping = (ComplexPropertyMapping)propertyMapping;
                ComplexTypeMapping     complexTypeMapping     = complexPropertyMapping.TypeMappings.Single <ComplexTypeMapping>();
                MappingFragment.RemoveColumnMapping((StructuralTypeMapping)complexTypeMapping, propertyPath.Skip <EdmProperty>(1));
                if (complexTypeMapping.PropertyMappings.Any <PropertyMapping>())
                {
                    return;
                }
                structuralTypeMapping.RemovePropertyMapping((PropertyMapping)complexPropertyMapping);
            }
        }
예제 #31
0
		/// <summary>
		/// Loop through all the specified properties, including the children of any complex type properties, looking for enum types.
		/// </summary>
		/// <param name="properties">The properties to search.</param>
		/// <param name="mappingFragment">Information needed from ef metadata to map table and its columns</param>
		/// <param name="objectItemCollection">For looking up ClrTypes of any enums encountered</param>
		/// <returns>All the references that were found in a form suitable for creating lookup tables and foreign keys</returns>
		private static IEnumerable<EnumReference> ProcessEdmProperties(IEnumerable<EdmProperty> properties, MappingFragment mappingFragment, ObjectItemCollection objectItemCollection)
		{
			var references = new List<EnumReference>();

			// get mapped table name from mapping, or fall-back to just the name if no mapping is set,
			// I have no idea what causes Table to be null, and I have no unit test for it yet, but I have seen it.
			var table = mappingFragment.StoreEntitySet.Table ?? mappingFragment.StoreEntitySet.Name;

			foreach (var edmProperty in properties)
			{
				if (edmProperty.IsEnumType)
				{
					references.Add(new EnumReference
					{
						ReferencingTable = table,
						ReferencingField = GetColumnName(mappingFragment, edmProperty),
						EnumType = objectItemCollection.GetClrType(edmProperty.EnumType),
					});
					continue;
				}

				if (edmProperty.IsComplexType)
				{
					// Note that complex types can't be nested (ref http://stackoverflow.com/a/20332503/10245 )
					// so it's safe to not recurse even though the data model suggests you should have to.
					references.AddRange(
						from nestedProperty in edmProperty.ComplexType.Properties
						where nestedProperty.IsEnumType
						select new EnumReference
						{
							ReferencingTable = table,
							ReferencingField = GetColumnName(mappingFragment, edmProperty, nestedProperty),
							EnumType = objectItemCollection.GetClrType(nestedProperty.EnumType),
						});
				}
			}

			return references;
		}
예제 #32
0
        public void Can_add_remove_mapping_fragment()
        {
            var storageSetMapping
                = new EntitySetMapping(
                    new EntitySet(),
                    new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));

            var storageTypeMapping
                = new EntityTypeMapping(storageSetMapping);

            Assert.Empty(storageTypeMapping.MappingFragments);

            var mappingFragment = new MappingFragment(new EntitySet(), storageTypeMapping, false);

            storageTypeMapping.AddFragment(mappingFragment);

            Assert.Same(mappingFragment, storageTypeMapping.MappingFragments.Single());

            storageTypeMapping.RemoveFragment(mappingFragment);

            Assert.Empty(storageTypeMapping.MappingFragments);
        }
예제 #33
0
        public void Can_add_and_remove_properties()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.PropertyMappings);

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            Assert.Same(scalarPropertyMapping, mappingFragment.PropertyMappings.Single());

            mappingFragment.RemovePropertyMapping(scalarPropertyMapping);

            Assert.Empty(mappingFragment.PropertyMappings);
        }
        public void Cannot_add_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            mappingFragment.SetReadOnly();

            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(
                    () => mappingFragment.AddPropertyMapping(scalarPropertyMapping)).Message);
        }
예제 #35
0
        public void Can_add_remove_mapping_fragment()
        {
            var storageSetMapping
                = new EntitySetMapping(
                      new EntitySet(),
                      new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)));

            var storageTypeMapping
                = new EntityTypeMapping(storageSetMapping);

            Assert.Empty(storageTypeMapping.MappingFragments);

            var mappingFragment = new MappingFragment(new EntitySet(), storageTypeMapping, false);

            storageTypeMapping.AddFragment(mappingFragment);

            Assert.Same(mappingFragment, storageTypeMapping.MappingFragments.Single());

            storageTypeMapping.RemoveFragment(mappingFragment);

            Assert.Empty(storageTypeMapping.MappingFragments);
        }
        public void Can_update_complex_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })), new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            }));

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var complexPropertyMapping = (ComplexPropertyMapping)mappingFragment.PropertyMappings.Single();

            var typeMapping = complexPropertyMapping.TypeMappings.Single();

            var scalarPropertyMapping = (ScalarPropertyMapping)typeMapping.PropertyMappings.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.Column);
            Assert.Same(property2, scalarPropertyMapping.Property);
        }
        public void Cannot_add_duplicate_column_mapping_builder()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            var columnMappingBuilder =
                new ColumnMappingBuilder(new EdmProperty("S", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })), new[] { new EdmProperty("S") });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws <ArgumentException>(
                    () => mappingFragment.AddColumnMapping(columnMappingBuilder)).Message);
        }
        public void GetPropertyMapping_should_return_mapping_with_path()
        {
            var entityTypeMapping = new EntityTypeMapping(null);
            var propertyFoo = EdmProperty.CreateComplex("Foo", new ComplexType("CT"));
            var propertyBar = EdmProperty.CreatePrimitive("Bar", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            var entityPropertyMapping
                = new ColumnMappingBuilder(
                    new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })),
                    new[]
                        {
                            propertyFoo,
                            propertyBar,
                        });

            var entityTypeMappingFragment
                = new MappingFragment(new EntitySet(), entityTypeMapping, false);

            entityTypeMappingFragment.AddColumnMapping(entityPropertyMapping);
            entityTypeMapping.AddFragment(entityTypeMappingFragment);

            Assert.Same(entityPropertyMapping, entityTypeMapping.GetPropertyMapping(propertyFoo, propertyBar));
        }
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                      new EntitySet(),
                      new EntityTypeMapping(
                          new EntitySetMapping(
                              new EntitySet(),
                              new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType()
            {
                DataSpace = DataSpace.SSpace
            })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
예제 #40
0
        /// <summary>
        /// Removes a mapping fragment.
        /// </summary>
        /// <param name="fragment">The mapping fragment to be removed.</param>
        public void RemoveFragment(MappingFragment fragment)
        {
            Check.NotNull(fragment, "fragment");
            ThrowIfReadOnly();

            _fragments.Remove(fragment);
        }
예제 #41
0
 internal void RemoveColumnMapping(ColumnMappingBuilder columnMappingBuilder)
 {
     this._columnMappings.Remove(columnMappingBuilder);
     MappingFragment.RemoveColumnMapping((StructuralTypeMapping)this, (IEnumerable <EdmProperty>)columnMappingBuilder.PropertyPath);
 }
예제 #42
0
        public void Can_add_scalar_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            var property = new EdmProperty("P");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());

            var scalarPropertyMapping = (ScalarPropertyMapping)mappingFragment.PropertyMappings.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.Column);
            Assert.Same(property, scalarPropertyMapping.Property);
        }
예제 #43
0
        /// <summary>
        /// Adds a mapping fragment.
        /// </summary>
        /// <param name="fragment">The mapping fragment to be added.</param>
        public void AddFragment(MappingFragment fragment)
        {
            Check.NotNull(fragment, "fragment");
            ThrowIfReadOnly();

            _fragments.Add(fragment);
        }
예제 #44
0
        public void Cannot_remove_property_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);

            mappingFragment.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mappingFragment.RemovePropertyMapping(scalarPropertyMapping)).Message);
        }
예제 #45
0
 /// <summary>Removes a mapping fragment.</summary>
 /// <param name="fragment">The mapping fragment to be removed.</param>
 public void RemoveFragment(MappingFragment fragment)
 {
     Check.NotNull <MappingFragment>(fragment, nameof(fragment));
     this.ThrowIfReadOnly();
     this._fragments.Remove(fragment);
 }
        public void Generate(
            EntityType entityType,
            IEnumerable<EdmProperty> properties,
            EntitySetMapping entitySetMapping,
            MappingFragment entityTypeMappingFragment,
            IList<EdmProperty> propertyPath,
            bool createNewColumn)
        {
            DebugCheck.NotNull(entityType);
            DebugCheck.NotNull(properties);
            DebugCheck.NotNull(entityTypeMappingFragment);
            DebugCheck.NotNull(propertyPath);

            var rootDeclaredProperties = entityType.GetRootType().DeclaredProperties;

            foreach (var property in properties)
            {
                if (property.IsComplexType
                    && propertyPath.Any(
                        p => p.IsComplexType
                             && (p.ComplexType == property.ComplexType)))
                {
                    throw Error.CircularComplexTypeHierarchy();
                }

                propertyPath.Add(property);

                if (property.IsComplexType)
                {
                    Generate(
                        entityType,
                        property.ComplexType.Properties,
                        entitySetMapping,
                        entityTypeMappingFragment,
                        propertyPath,
                        createNewColumn);
                }
                else
                {
                    var tableColumn
                        = entitySetMapping.EntityTypeMappings
                                          .SelectMany(etm => etm.MappingFragments)
                                          .SelectMany(etmf => etmf.ColumnMappings)
                                          .Where(pm => pm.PropertyPath.SequenceEqual(propertyPath))
                                          .Select(pm => pm.ColumnProperty)
                                          .FirstOrDefault();

                    if (tableColumn == null || createNewColumn)
                    {
                        var columnName
                            = string.Join("_", propertyPath.Select(p => p.Name));

                        tableColumn
                            = MapTableColumn(
                                property,
                                columnName,
                                !rootDeclaredProperties.Contains(propertyPath.First()));

                        entityTypeMappingFragment.Table.AddColumn(tableColumn);

                        if (entityType.KeyProperties().Contains(property))
                        {
                            entityTypeMappingFragment.Table.AddKeyMember(tableColumn);
                        }
                    }

                    entityTypeMappingFragment.AddColumnMapping(
                        new ColumnMappingBuilder(tableColumn, propertyPath.ToList()));
                }

                propertyPath.Remove(property);
            }
        }
        public static void MovePropertyMapping(
            DbDatabaseMapping databaseMapping,
            IEnumerable<EntitySet> entitySets,
            MappingFragment fromFragment,
            MappingFragment toFragment,
            ColumnMappingBuilder propertyMappingBuilder,
            bool requiresUpdate,
            bool useExisting)
        {
            // move the column from the formTable to the table in fragment
            if (requiresUpdate && fromFragment.Table != toFragment.Table)
            {
                UpdatePropertyMapping(databaseMapping, entitySets, GetColumnMappingIndex(databaseMapping), propertyMappingBuilder, fromFragment.Table, toFragment.Table, useExisting);
            }

            // move the propertyMapping
            fromFragment.RemoveColumnMapping(propertyMappingBuilder);
            toFragment.AddColumnMapping(propertyMappingBuilder);
        }
예제 #48
0
        public void Can_get_and_set_table_set()
        {
            var tableSet = new EntitySet();

            var mappingFragment
                = new MappingFragment(
                    tableSet,
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Same(tableSet, mappingFragment.TableSet);

            tableSet = new EntitySet();

            mappingFragment.TableSet = tableSet;

            Assert.Same(tableSet, mappingFragment.TableSet);
        }
 public static void UpdateConditions(
     EdmModel database, EntityType fromTable, MappingFragment fragment)
 {
     // move the condition's column from the formTable to the table in fragment
     if (fromTable != fragment.Table)
     {
         fragment.ColumnConditions.Each(
             cc =>
             {
                 cc.Column
                     = TableOperations.CopyColumnAndAnyConstraints(
                         database, fromTable, fragment.Table, cc.Column,
                         TablePrimitiveOperations.GetNameMatcher(cc.Column.Name),
                         useExisting: true);
             });
     }
 }
예제 #50
0
        public void SetReadOnly_is_called_on_child_mapping_items()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var scalarPropertyMapping = new ScalarPropertyMapping(new EdmProperty("P"), new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })));
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddPropertyMapping(scalarPropertyMapping);
            mappingFragment.AddCondition(conditionMapping);

            Assert.False(scalarPropertyMapping.IsReadOnly);
            Assert.False(conditionMapping.IsReadOnly);
            mappingFragment.SetReadOnly();
            Assert.True(scalarPropertyMapping.IsReadOnly);
            Assert.True(conditionMapping.IsReadOnly);
        }
예제 #51
0
        public void Can_get_table()
        {
            var table = new EntityType("E", "N", DataSpace.CSpace);

            var tableSet = new EntitySet("ES", null, null, null, table);

            var mappingFragment
                = new MappingFragment(
                    tableSet,
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Same(table, mappingFragment.Table);
        }
예제 #52
0
        public void Can_add_and_remove_column_conditions()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnConditions);

            var conditionPropertyMapping
                = new ConditionPropertyMapping(null, new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), 42, null);

            mappingFragment.AddConditionProperty(conditionPropertyMapping);

            Assert.Same(conditionPropertyMapping, mappingFragment.ColumnConditions.Single());

            mappingFragment.RemoveConditionProperty(conditionPropertyMapping);

            Assert.Empty(mappingFragment.ColumnConditions);
        }
        public static MappingFragment CreateTypeMappingFragment(
            EntityTypeMapping entityTypeMapping, MappingFragment templateFragment, EntitySet tableSet)
        {
            var fragment = new MappingFragment(tableSet, entityTypeMapping, false);

            entityTypeMapping.AddFragment(fragment);

            // Move all PK mappings to the extra fragment
            foreach (
                var pkPropertyMapping in templateFragment.ColumnMappings.Where(pm => pm.ColumnProperty.IsPrimaryKeyColumn))
            {
                CopyPropertyMappingToFragment(
                    pkPropertyMapping, fragment, TablePrimitiveOperations.GetNameMatcher(pkPropertyMapping.ColumnProperty.Name),
                    useExisting: true);

            }
            return fragment;
        }
예제 #54
0
        public void Can_remove_complex_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            Assert.Empty(mappingFragment.ColumnMappings);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));
            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Same(columnMappingBuilder, mappingFragment.ColumnMappings.Single());
            Assert.NotEmpty(mappingFragment.PropertyMappings);

            mappingFragment.RemoveColumnMapping(columnMappingBuilder);

            Assert.Empty(mappingFragment.ColumnMappings);
            Assert.Empty(mappingFragment.PropertyMappings);
        }
 public static void UpdatePropertyMappings(
     DbDatabaseMapping databaseMapping,
     IEnumerable<EntitySet> entitySets,
     EntityType fromTable,
     MappingFragment fragment,
     bool useExisting)
 {
     // PERF: this code is part of a hotpath, consider its performance when refactoring
     // move the column from the fromTable to the table in fragment
     if (fromTable != fragment.Table)
     {
         var columnMappingIndex = GetColumnMappingIndex(databaseMapping);
         var columnMappings = fragment.ColumnMappings.ToList();
         for (var i = 0; i < columnMappings.Count; ++i)
         {
             UpdatePropertyMapping(databaseMapping, entitySets, columnMappingIndex, columnMappings[i], fromTable, fragment.Table, useExisting);
         }
     }
 }
예제 #56
0
        public void Cannot_add_duplicate_column_mapping_builder()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            var columnMappingBuilder =
                new ColumnMappingBuilder(new EdmProperty("S", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { new EdmProperty("S") });

            mappingFragment.AddColumnMapping(columnMappingBuilder);

            Assert.Equal(
                Strings.InvalidColumnBuilderArgument("columnBuilderMapping"),
                Assert.Throws<ArgumentException>(
                () => mappingFragment.AddColumnMapping(columnMappingBuilder)).Message);            
        }
        public static void CopyPropertyMappingToFragment(
            ColumnMappingBuilder propertyMappingBuilder, MappingFragment fragment,
            Func<EdmProperty, bool> isCompatible, bool useExisting)
        {
            // Ensure column is in the fragment's table
            var column = TablePrimitiveOperations.IncludeColumn(fragment.Table, propertyMappingBuilder.ColumnProperty, isCompatible, useExisting);

            // Add the property mapping
            fragment.AddColumnMapping(
                new ColumnMappingBuilder(column, propertyMappingBuilder.PropertyPath));
        }
예제 #58
0
        public void Cannot_remove_condition_when_read_only()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);
            var conditionMapping = new IsNullConditionMapping(new EdmProperty("P"), true);

            mappingFragment.AddCondition(conditionMapping);

            mappingFragment.SetReadOnly();

            Assert.Equal(
                Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(
                    () => mappingFragment.RemoveCondition(conditionMapping)).Message);
        }
예제 #59
0
        public void Can_update_complex_column_mapping()
        {
            var mappingFragment
                = new MappingFragment(
                    new EntitySet(),
                    new EntityTypeMapping(
                        new EntitySetMapping(
                            new EntitySet(),
                            new EntityContainerMapping(new EntityContainer("C", DataSpace.CSpace)))), false);

            var property1 = EdmProperty.CreateComplex("P1", new ComplexType("CT"));
            var property2 = new EdmProperty("P2");

            var columnMappingBuilder1 = new ColumnMappingBuilder(new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace })), new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder1);

            var columnProperty = new EdmProperty("C", TypeUsage.Create(new PrimitiveType() { DataSpace = DataSpace.SSpace }));

            var columnMappingBuilder2 = new ColumnMappingBuilder(columnProperty, new[] { property1, property2 });

            mappingFragment.AddColumnMapping(columnMappingBuilder2);

            var complexPropertyMapping = (ComplexPropertyMapping)mappingFragment.PropertyMappings.Single();

            var typeMapping = complexPropertyMapping.TypeMappings.Single();

            var scalarPropertyMapping = (ScalarPropertyMapping)typeMapping.PropertyMappings.Single();

            Assert.Same(columnProperty, scalarPropertyMapping.Column);
            Assert.Same(property2, scalarPropertyMapping.Property);
        }
예제 #60
0
 public static string GetIdentity(MappingFragment mapping)
 {
     return(mapping.TableSet.Identity);
 }