예제 #1
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());
        }
 protected virtual void Visit(EntityContainer entityContainer)
 {
     foreach (var set in entityContainer.BaseEntitySets)
     {
         Visit(set);
     }
 }
        public void Can_clear_modification_function_mappings()
        {
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("S", "N", null, null, entityType);
            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddEntitySetBase(entitySet);

            var entitySetMapping =
                new StorageEntitySetMapping(
                    entitySet,
                    new StorageEntityContainerMapping(container));

            var functionMapping =
                new StorageModificationFunctionMapping(
                    entitySet,
                    entityType,
                    function,
                    Enumerable.Empty<StorageModificationFunctionParameterBinding>(),
                    null,
                    null);

            var entityFunctionMappings =
                new StorageEntityTypeModificationFunctionMapping(entityType, functionMapping, null, null);

            entitySetMapping.AddModificationFunctionMapping(entityFunctionMappings);

            Assert.Equal(1, entitySetMapping.ModificationFunctionMappings.Count());

            entitySetMapping.ClearModificationFunctionMappings();

            Assert.Equal(0, entitySetMapping.ModificationFunctionMappings.Count());
        }
예제 #4
0
        private EdmModel(EntityContainer entityContainer, double version = XmlConstants.SchemaVersionLatest)
        {
            DebugCheck.NotNull(entityContainer);

            _container = entityContainer;
            SchemaVersion = version;
        }
        public void Can_set_and_get_name()
        {
            var entityContainer
                = new EntityContainer("Foo", DataSpace.CSpace);

            Assert.Equal("Foo", entityContainer.Name);
        }
        public void VisitEdmEntityContainer_visits_function_imports()
        {
            var functionPayload =
                new EdmFunctionPayload
                    {
                        IsFunctionImport = true
                    };

            var functionImport =
                new EdmFunction("f", "N", DataSpace.CSpace, functionPayload);

            var container = new EntityContainer("C", DataSpace.CSpace);
            container.AddFunctionImport(functionImport);

            var visitorMock =
                new Mock<EdmModelVisitor>
                    {
                        CallBase = true
                    };

            visitorMock.Object.VisitEdmModel(new EdmModel(container));

            visitorMock.Verify(v => v.VisitFunctionImports(container, It.IsAny<IEnumerable<EdmFunction>>()), Times.Once());
            visitorMock.Verify(v => v.VisitFunctionImport(functionImport), Times.Once());
        }
예제 #7
0
        public EdmModel(EntityContainer entityContainer, double version = XmlConstants.SchemaVersionLatest)
        {
            Check.NotNull(entityContainer, "entityContainer");

            _dataSpace = entityContainer.DataSpace;
            _containers.Add(entityContainer);
            SchemaVersion = version;
        }
        public void Custom_container_set_correctly()
        {
            var container = new EntityContainer("MyContainer", DataSpace.CSpace);

            Assert.Same(
                container,
                new EdmModel(container).Containers.Single());
        }
예제 #9
0
        // <summary>
        // Returns the entity container in CSpace or SSpace
        // </summary>
        internal override bool TryGetEntityContainer(string name, bool ignoreCase, out EntityContainer entityContainer)
        {
            if (!base.TryGetEntityContainer(name, ignoreCase, out entityContainer))
            {
                return _modelPerspective.TryGetEntityContainer(name, ignoreCase, out entityContainer);
            }

            return true;
        }
예제 #10
0
        /// <summary>
        /// Gets the type identifier for the specified container.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <returns>The identifier.</returns>
        public string Type(EntityContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            return Identifier(container.Name);
        }
        public void Can_get_collection_of_entity_sets()
        {
            var entityContainer = new EntityContainer("C", DataSpace.CSpace);

            entityContainer.AddEntitySetBase(new EntitySet("E", null, null, null, new EntityType("E", "N", DataSpace.CSpace)));

            Assert.Equal(1, entityContainer.EntitySets.Count);
            Assert.Empty(entityContainer.AssociationSets);
        }
        public void Can_get_collection_of_association_sets()
        {
            var entityContainer = new EntityContainer("C", DataSpace.CSpace);

            entityContainer.AddEntitySetBase(new AssociationSet("A", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)));

            Assert.Equal(1, entityContainer.AssociationSets.Count);
            Assert.Empty(entityContainer.EntitySets);
        }
예제 #13
0
 internal bool TryGetEntityContainer(EntitySetBase item, out EntityContainer container)
 {
     if (item != null)
     {
         return itemToContainerMap.TryGetValue(item, out container);
     }
     container = null;
     return false;
 }
예제 #14
0
        public void Can_set_and_get_name()
        {
            var entityContainer
                = new EntityContainer
                      {
                          Name = "Foo"
                      };

            Assert.Equal("Foo", entityContainer.Name);
        }
        public void Can_get_store_and_entity_containers()
        {
            var entityContainer = new EntityContainer("C", DataSpace.CSpace);
            var storeContainer = new EntityContainer("S", DataSpace.CSpace);
            var entityContainerMapping = 
                new EntityContainerMapping(entityContainer, storeContainer, null, false, false);

            Assert.Same(entityContainer, entityContainerMapping.EdmEntityContainer);
            Assert.Same(storeContainer, entityContainerMapping.StorageEntityContainer);
        }
        public DbMapping(DbContext context)
        {
            _context = context;

              var objectContext = ((IObjectContextAdapter)context).ObjectContext;
              _metadataWorkspace = objectContext.MetadataWorkspace;

              _codeFirstEntityContainer = _metadataWorkspace.GetEntityContainer("CodeFirstDatabase", DataSpace.SSpace);

              MapDb();
        }
 /// <summary>
 ///     Returns mappings for the given set/type only if the mapping applies also to childEntittyType either via IsTypeOf or explicitly specifying multiple types in mapping fragments.
 /// </summary>
 private static IEnumerable<StorageTypeMapping> GetIsTypeOfMappingsForEntitySetAndType(
     StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType,
     EntityTypeBase childEntityType)
 {
     foreach (var mapping in GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityType))
     {
         if (mapping.IsOfTypes.Any(parentType => parentType.IsAssignableFrom(childEntityType))
             || mapping.Types.Contains(childEntityType))
         {
             yield return mapping;
         }
     }
 }
예제 #18
0
        // <summary>
        // Load all relationships in this entity container
        // </summary>
        internal void LoadRelationships(md.EntityContainer entityContainer)
        {
            // Check to see if I've already loaded information for this entity container
            if (m_entityContainerMap.ContainsKey(entityContainer))
            {
                return;
            }

            // Load all relationships from this entitycontainer
            foreach (var e in entityContainer.BaseEntitySets)
            {
                var relationshipSet = e as md.RelationshipSet;
                if (relationshipSet == null)
                {
                    continue;
                }

                // Relationship sets can only contain relationships
                var relationshipType = relationshipSet.ElementType;
                var assocType        = relationshipType as md.AssociationType;

                //
                // Handle only binary Association relationships for now
                //
                if (null == assocType ||
                    !IsBinary(relationshipType))
                {
                    continue;
                }

                foreach (var constraint in assocType.ReferentialConstraints)
                {
                    List <ForeignKeyConstraint> fkConstraintList;
                    var fkConstraint = new ForeignKeyConstraint(relationshipSet, constraint);
                    if (!m_parentChildRelationships.TryGetValue(fkConstraint.Pair, out fkConstraintList))
                    {
                        fkConstraintList = new List <ForeignKeyConstraint>();
                        m_parentChildRelationships[fkConstraint.Pair] = fkConstraintList;
                    }
                    //
                    // Theoretically, we can have more than one fk constraint between
                    // the 2 tables (though, it is unlikely)
                    //
                    fkConstraintList.Add(fkConstraint);
                }
            }

            // Mark this entity container as already loaded
            m_entityContainerMap[entityContainer] = entityContainer;
        }
 /// <summary>
 ///     Returns all mapping fragments for the given entity set's types and their parent types.
 /// </summary>
 internal static IEnumerable<StorageTypeMapping> GetMappingsForEntitySetAndSuperTypes(
     StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet,
     EntityTypeBase childEntityType)
 {
     return MetadataHelper.GetTypeAndParentTypesOf(childEntityType, true /*includeAbstractTypes*/).SelectMany(
         edmType =>
             {
                 var entityTypeBase = edmType as EntityTypeBase;
                 return edmType.EdmEquals(childEntityType)
                            ? GetMappingsForEntitySetAndType(mappingCollection, container, entitySet, entityTypeBase)
                            : GetIsTypeOfMappingsForEntitySetAndType(
                                mappingCollection, container, entitySet, entityTypeBase, childEntityType);
             }).ToList();
 }
        public void Can_remove_set_from_container()
        {
            var entityContainer = new EntityContainer("C", DataSpace.CSpace);
            var associationSet = new AssociationSet("A", new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace));

            entityContainer.AddEntitySetBase(associationSet);

            Assert.Equal(1, entityContainer.AssociationSets.Count);

            entityContainer.RemoveEntitySetBase(associationSet);

            Assert.Empty(entityContainer.AssociationSets);
            Assert.Null(associationSet.EntityContainer);
        }
예제 #21
0
        internal EdmModel(DataSpace dataSpace, double schemaVersion = XmlConstants.SchemaVersionLatest)
        {
            if (dataSpace != DataSpace.CSpace && dataSpace != DataSpace.SSpace)
            {
                throw new ArgumentException(Strings.MetadataItem_InvalidDataSpace(dataSpace, typeof(EdmModel).Name), "dataSpace");
            }

            _container = new EntityContainer(
                dataSpace == DataSpace.CSpace
                    ? "CodeFirstContainer"
                    : "CodeFirstDatabase",
                dataSpace);

            _schemaVersion = schemaVersion;
        }
예제 #22
0
        public void WriteEntitySetMappingElement_should_write_modification_function_mappings()
        {
            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));

            var storageModificationFunctionMapping
                = new ModificationFunctionMapping(
                    entitySet,
                    entityType,
                    new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload()),
                    Enumerable.Empty<ModificationFunctionParameterBinding>(),
                    null,
                    null);

            storageEntitySetMapping.AddModificationFunctionMapping(
                new EntityTypeModificationFunctionMapping(
                    entityType,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping,
                    storageModificationFunctionMapping));

            fixture.Writer.WriteEntitySetMappingElement(storageEntitySetMapping);

            Assert.Equal(
                @"<EntitySetMapping Name=""ES"">
  <EntityTypeMapping TypeName="".E"">
    <ModificationFunctionMapping>
      <InsertFunction FunctionName=""N.F"" />
      <UpdateFunction FunctionName=""N.F"" />
      <DeleteFunction FunctionName=""N.F"" />
    </ModificationFunctionMapping>
  </EntityTypeMapping>
</EntitySetMapping>",
                fixture.ToString());
        }
        internal static IEnumerable<StorageTypeMapping> GetMappingsForEntitySetAndType(
            StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType)
        {
            DebugCheck.NotNull(entityType);
            var containerMapping = GetEntityContainerMap(mappingCollection, container);
            var extentMap = containerMapping.GetSetMapping(entitySet.Name);

            //The Set may have no mapping
            if (extentMap != null)
            {
                //for each mapping fragment of Type we are interested in within the given set
                //Check use of IsOfTypes in Code review
                foreach (var typeMap in extentMap.TypeMappings.Where(map => map.Types.Union(map.IsOfTypes).Contains(entityType)))
                {
                    yield return typeMap;
                }
            }
        }
예제 #24
0
 // <summary>
 // Returns the function import in the target space, for the given entity container.
 // </summary>
 internal virtual bool TryGetFunctionImport(
     EntityContainer entityContainer, String functionImportName, bool ignoreCase, out EdmFunction functionImport)
 {
     // There are no entity containers in the OSpace. So there is no mapping involved.
     // Hence the name should be a valid name in the CSpace.
     functionImport = null;
     if (ignoreCase)
     {
         functionImport =
             entityContainer.FunctionImports.Where(
                 fi => String.Equals(fi.Name, functionImportName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
     }
     else
     {
         functionImport = entityContainer.FunctionImports.Where(fi => fi.Name == functionImportName).SingleOrDefault();
     }
     return functionImport != null;
 }
            private Dictionary<EntitySetBase, GeneratedView> SerializedGetGeneratedViews(EntityContainer container)
            {
                DebugCheck.NotNull(container);

                // Note that extentMappingViews will contain both query and update views.
                Dictionary<EntitySetBase, GeneratedView> extentMappingViews;

                // Get the mapping that has the entity container mapped.
                var entityContainerMap = MappingMetadataHelper.GetEntityContainerMap(_storageMappingItemCollection, container);

                // We get here because memoizer didn't find an entry for the container.
                // It might happen that the entry with generated views already exists for the counterpart container, so check it first.
                var counterpartContainer = container.DataSpace == DataSpace.CSpace
                                               ? entityContainerMap.StorageEntityContainer
                                               : entityContainerMap.EdmEntityContainer;
                if (_generatedViewsMemoizer.TryGetValue(counterpartContainer, out extentMappingViews))
                {
                    return extentMappingViews;
                }

                extentMappingViews = new Dictionary<EntitySetBase, GeneratedView>();

                if (!entityContainerMap.HasViews)
                {
                    return extentMappingViews;
                }

                // If we are in generated views mode.
                if (_generatedViewsMode && _storageMappingItemCollection.MappingViewCacheFactory != null)
                {
                    SerializedCollectViewsFromCache(entityContainerMap, extentMappingViews);
                }

                if (extentMappingViews.Count == 0)
                {
                    // We should change the mode to runtime generation of views.
                    _generatedViewsMode = false;
                    SerializedGenerateViews(entityContainerMap, extentMappingViews);
                }

                Debug.Assert(extentMappingViews.Count > 0, "view should be generated at this point");

                return extentMappingViews;
            }
        public void Can_get_rows_affected_parameter_name()
        {
            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 storageModificationFunctionMapping
                = new StorageModificationFunctionMapping(
                    entitySet,
                    entityType,
                    new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload()),
                    Enumerable.Empty<StorageModificationFunctionParameterBinding>(),
                    new FunctionParameter("rows_affected", new TypeUsage(), ParameterMode.Out),
                    null);

            Assert.Equal("rows_affected", storageModificationFunctionMapping.RowsAffectedParameterName);
        }
예제 #27
0
        // effects: Given a store-side container, returns all the foreign key
        // constraints specified for different tables
        internal static List<ForeignConstraint> GetForeignConstraints(EntityContainer container)
        {
            var foreignKeyConstraints = new List<ForeignConstraint>();

            // Go through all the extents and get the associations
            foreach (var extent in container.BaseEntitySets)
            {
                var relationSet = extent as AssociationSet;

                if (relationSet == null)
                {
                    continue;
                }
                // Keep track of the end to EntitySet mapping
                var endToExtents = new Dictionary<string, EntitySet>();

                foreach (var end in relationSet.AssociationSetEnds)
                {
                    endToExtents.Add(end.Name, end.EntitySet);
                }

                var relationType = relationSet.ElementType;
                // Go through each referential constraint, determine the name
                // of the tables that the constraint refers to and then
                // create the foreign key constraint between the tables
                // Wow! We go to great lengths to make it cumbersome for a
                // programmer to deal with foreign keys
                foreach (var constraint in relationType.ReferentialConstraints)
                {
                    // Note: We are correlating the constraint's roles with
                    // the ends above using the role names, i.e.,
                    // FromRole.Name and ToRole.Name here and end.Role above
                    var parentExtent = endToExtents[constraint.FromRole.Name];
                    var childExtent = endToExtents[constraint.ToRole.Name];
                    var foreignKeyConstraint = new ForeignConstraint(
                        relationSet, parentExtent, childExtent,
                        constraint.FromProperties, constraint.ToProperties);
                    foreignKeyConstraints.Add(foreignKeyConstraint);
                }
            }
            return foreignKeyConstraints;
        }
        protected override void Visit(EntityContainer entityContainer)
        {
            int index;
            if (!AddObjectToSeenListAndHashBuilder(entityContainer, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(entityContainer, index);

            #region Inner data visit

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

            base.Visit(entityContainer);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }
예제 #29
0
        private IEnumerable<DynamicFilterDefinition> FindFiltersForEntitySet(ReadOnlyMetadataCollection<MetadataProperty> metadataProperties, EntityContainer entityContainer)
        {
            var filterList = metadataProperties
                .Where(mp => mp.Name.Contains("customannotation:" + DynamicFilterConstants.ATTRIBUTE_NAME_PREFIX))
                .Select(m => m.Value as DynamicFilterDefinition)
                .ToList();

            if (filterList.Any())
            {
                //  Recursively remove any filters that exist in base EntitySets to this entity.
                //  This happens when an entity uses Table-per-Type inheritance.  Filters will be added
                //  to all derived EntitySets because of the inheritance in the C# classes.  But the database
                //  representation (the EntitySet) does not give access to inherited propeties since they
                //  only exist in the child EntitySet.  And on queries of entities involved in TPT, the
                //  query will generate a DbScanExpression for each EntitySet - so we only want the filters
                //  applied to the DbScanExpression to which they apply.
                //  See issue #32.
                RemoveFiltersForBaseClass(filterList.First().CLRType, filterList, entityContainer);
            }

            return filterList;
        }
        internal static IEnumerable<StorageEntityTypeModificationFunctionMapping> GetModificationFunctionMappingsForEntitySetAndType(
            StorageMappingItemCollection mappingCollection, EntityContainer container, EntitySetBase entitySet, EntityTypeBase entityType)
        {
            var containerMapping = GetEntityContainerMap(mappingCollection, container);

            var extentMap = containerMapping.GetSetMapping(entitySet.Name);
            var entitySetMapping = extentMap as StorageEntitySetMapping;

            //The Set may have no mapping
            if (entitySetMapping != null)
            {
                if (entitySetMapping != null) //could be association set mapping
                {
                    foreach (
                        var v in
                            entitySetMapping.ModificationFunctionMappings.Where(functionMap => functionMap.EntityType.Equals(entityType)))
                    {
                        yield return v;
                    }
                }
            }
        }
        public void Can_retrieve_properties()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", "T", "Q", entityType);
            var entityContainer = new EntityContainer("EC", DataSpace.SSpace);

            entityContainer.AddEntitySetBase(entitySet);

            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());
            var parameterBindings
                = new[]
                  {
                      new ModificationFunctionParameterBinding(
                          new FunctionParameter(), 
                          new ModificationFunctionMemberPath(Enumerable.Empty<EdmMember>(), null),
                          true)
                  };
            var rowsAffectedParameter = new FunctionParameter("rows_affected", new TypeUsage(), ParameterMode.Out);

            var resultBindings
                = new[]
                  {
                      new ModificationFunctionResultBinding(
                          "C", 
                          EdmProperty.CreatePrimitive(
                              "P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))
                  };

            var mapping
                = new ModificationFunctionMapping(
                    entitySet, entityType, function,
                    parameterBindings, rowsAffectedParameter, resultBindings);

            Assert.Same(rowsAffectedParameter, mapping.RowsAffectedParameter);
            Assert.Same(function, mapping.Function);
            Assert.Equal(parameterBindings, mapping.ParameterBindings);
            Assert.Equal(resultBindings, mapping.ResultBindings);
        }
        /// <summary>
        /// The factory method for constructing the EntityContainer object.
        /// </summary>
        /// <param name="name">The name of the entity container to be created.</param>
        /// <param name="dataSpace">DataSpace in which this entity container belongs to.</param>
        /// <param name="entitySets">Entity sets that will be included in the new container. Can be null.</param>
        /// <param name="functionImports">Functions that will be included in the new container. Can be null.</param>
        /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param>
        /// <returns>The EntityContainer object.</returns>
        /// <exception cref="System.ArgumentException">Thrown if the name argument is null or empty string.</exception>
        /// <remarks>The newly created EntityContainer will be read only.</remarks>
        public static EntityContainer Create(
            string name, DataSpace dataSpace, IEnumerable <EntitySetBase> entitySets,
            IEnumerable <EdmFunction> functionImports, IEnumerable <MetadataProperty> metadataProperties)
        {
            Check.NotEmpty(name, "name");

            var entityContainer = new EntityContainer(name, dataSpace);

            if (entitySets != null)
            {
                foreach (var entitySet in entitySets)
                {
                    entityContainer.AddEntitySetBase(entitySet);
                }
            }

            if (functionImports != null)
            {
                foreach (var function in functionImports)
                {
                    if (!function.IsFunctionImport)
                    {
                        throw new ArgumentException(Strings.OnlyFunctionImportsCanBeAddedToEntityContainer(function.Name));
                    }
                    entityContainer.AddFunctionImport(function);
                }
            }

            if (metadataProperties != null)
            {
                entityContainer.AddMetadataProperties(metadataProperties.ToList());
            }

            entityContainer.SetReadOnly();

            return(entityContainer);
        }
예제 #33
0
        public void Create_factory_method_sets_properties_and_seals_the_type()
        {
            var entitySets = new[] { new EntitySet { Name = "Bar"} };

            var functionImports =
                new[]
                    {
                        new EdmFunction(
                            "foo",
                            "bar",
                            DataSpace.CSpace,
                            new EdmFunctionPayload()
                                {
                                    IsFunctionImport = true
                                })
                    };


            var entityContainer =
                EntityContainer.Create("Foo", DataSpace.SSpace, entitySets, functionImports, 
                    new[]
                        {
                            new MetadataProperty(
                                "TestProperty",
                                TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)),
                                "value"),
                        });

            Assert.Equal("Foo", entityContainer.Name);
            Assert.Equal(entitySets, entityContainer.EntitySets);
            Assert.Equal(functionImports, entityContainer.FunctionImports);
            Assert.True(entityContainer.IsReadOnly);

            var metadataProperty = entityContainer.MetadataProperties.SingleOrDefault(p => p.Name == "TestProperty");
            Assert.NotNull(metadataProperty);
            Assert.Equal("value", metadataProperty.Value);
        }
예제 #34
0
 protected override void VisitEdmEntityContainer(EntityContainer item)
 {
     this._schemaWriter.WriteEntityContainerElementHeader(item);
     base.VisitEdmEntityContainer(item);
     this._schemaWriter.WriteEndElement();
 }
 internal virtual void WriteEntityContainerElementHeader(EntityContainer container)
 {
     this._xmlWriter.WriteStartElement("EntityContainer");
     this._xmlWriter.WriteAttributeString("Name", container.Name);
     this.WriteExtendedProperties((MetadataItem)container);
 }
예제 #36
0
 internal EntitySetBaseCollection(EntityContainer entityContainer)
     : this(entityContainer, (IEnumerable <EntitySetBase>)null)
 {
 }
예제 #37
0
 /// <summary>
 /// Returns an <see cref="T:System.Data.Entity.Core.Metadata.Edm.EntityContainer" /> object by using the specified entity container name. If there is no entity container, the output parameter contains null; otherwise, it contains the first entity container.
 /// </summary>
 /// <returns>true if there is an entity container that matches the search criteria; otherwise, false.</returns>
 /// <param name="name">The name of the entity container.</param>
 /// <param name="entityContainer">
 /// When this method returns, it contains an <see cref="T:System.Data.Entity.Core.Metadata.Edm.EntityContainer" /> object. If there is no entity container, this output parameter contains null; otherwise, it contains the first entity container.
 /// </param>
 public bool TryGetEntityContainer(string name, out EntityContainer entityContainer)
 {
     Check.NotNull <string>(name, nameof(name));
     return(this.TryGetEntityContainer(name, false, out entityContainer));
 }
예제 #38
0
 // <summary>
 // Change the entity container without doing fixup in the entity set collection
 // </summary>
 internal void ChangeEntityContainerWithoutCollectionFixup(EntityContainer newEntityContainer)
 {
     _entityContainer = newEntityContainer;
 }
 private static EntitySet GetEntitySet(
     EntityContainerEntitySet set,
     EntityContainer container)
 {
     return(container.GetEntitySetByName(set.Name, false));
 }
예제 #40
0
 // <summary>
 // Returns the extent in the target space, for the given entity container.
 // </summary>
 // <param name="entityContainer"> name of the entity container in target space </param>
 // <param name="extentName"> name of the extent </param>
 // <param name="ignoreCase"> Whether to do case-sensitive member look up or not </param>
 // <param name="outSet"> extent in target space, if a match is found </param>
 // <returns> returns true, if a match is found otherwise returns false </returns>
 internal virtual bool TryGetExtent(EntityContainer entityContainer, String extentName, bool ignoreCase, out EntitySetBase outSet)
 {
     // There are no entity containers in the OSpace. So there is no mapping involved.
     // Hence the name should be a valid name in the CSpace.
     return(entityContainer.BaseEntitySets.TryGetValue(extentName, ignoreCase, out outSet));
 }
예제 #41
0
 // <summary>
 // Get an entity container based upon the strong name of the container
 // If no entity container is found, returns null, else returns the first one//
 // </summary>
 // <param name="name"> name of the entity container </param>
 // <param name="ignoreCase"> true for case-insensitive lookup </param>
 // <param name="entityContainer"> returns the entity container if a match is found </param>
 // <returns> returns true if a match is found, otherwise false </returns>
 internal virtual bool TryGetEntityContainer(string name, bool ignoreCase, out EntityContainer entityContainer)
 {
     return(MetadataWorkspace.TryGetEntityContainer(name, ignoreCase, TargetDataspace, out entityContainer));
 }
        private static EdmFunction ConvertToFunction(
            System.Data.Entity.Core.SchemaObjectModel.Function somFunction,
            DbProviderManifest providerManifest,
            Converter.ConversionCache convertedItemCache,
            EntityContainer functionImportEntityContainer,
            Dictionary <SchemaElement, GlobalItem> newGlobalItems)
        {
            GlobalItem globalItem = (GlobalItem)null;

            if (!somFunction.IsFunctionImport && newGlobalItems.TryGetValue((SchemaElement)somFunction, out globalItem))
            {
                return((EdmFunction)globalItem);
            }
            bool areConvertingForProviderManifest           = somFunction.Schema.DataModel == SchemaDataModelOption.ProviderManifestModel;
            List <FunctionParameter> functionParameterList1 = new List <FunctionParameter>();

            if (somFunction.ReturnTypeList != null)
            {
                int num = 0;
                foreach (ReturnType returnType in (IEnumerable <ReturnType>)somFunction.ReturnTypeList)
                {
                    TypeUsage functionTypeUsage = Converter.GetFunctionTypeUsage(somFunction is ModelFunction, somFunction, (FacetEnabledSchemaElement)returnType, providerManifest, areConvertingForProviderManifest, returnType.Type, returnType.CollectionKind, returnType.IsRefType, convertedItemCache, newGlobalItems);
                    if (functionTypeUsage == null)
                    {
                        return((EdmFunction)null);
                    }
                    string str = num == 0 ? string.Empty : num.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                    ++num;
                    FunctionParameter functionParameter = new FunctionParameter("ReturnType" + str, functionTypeUsage, ParameterMode.ReturnValue);
                    Converter.AddOtherContent((SchemaElement)returnType, (MetadataItem)functionParameter);
                    functionParameterList1.Add(functionParameter);
                }
            }
            else if (somFunction.Type != null)
            {
                TypeUsage functionTypeUsage = Converter.GetFunctionTypeUsage(somFunction is ModelFunction, somFunction, (FacetEnabledSchemaElement)null, providerManifest, areConvertingForProviderManifest, somFunction.Type, somFunction.CollectionKind, somFunction.IsReturnAttributeReftype, convertedItemCache, newGlobalItems);
                if (functionTypeUsage == null)
                {
                    return((EdmFunction)null);
                }
                functionParameterList1.Add(new FunctionParameter("ReturnType", functionTypeUsage, ParameterMode.ReturnValue));
            }
            EntitySet[] entitySetArray = (EntitySet[])null;
            string      name;

            if (somFunction.IsFunctionImport)
            {
                FunctionImportElement functionImportElement = (FunctionImportElement)somFunction;
                name = functionImportElement.Container.Name;
                if (functionImportElement.EntitySet != null)
                {
                    EntityContainer container = functionImportEntityContainer;
                    entitySetArray = new EntitySet[1]
                    {
                        Converter.GetEntitySet(functionImportElement.EntitySet, container)
                    };
                }
                else if (functionImportElement.ReturnTypeList != null)
                {
                    EntityContainer entityContainer = functionImportEntityContainer;
                    entitySetArray = functionImportElement.ReturnTypeList.Select <ReturnType, EntitySet>((Func <ReturnType, EntitySet>)(returnType =>
                    {
                        if (returnType.EntitySet == null)
                        {
                            return((EntitySet)null);
                        }
                        return(Converter.GetEntitySet(returnType.EntitySet, functionImportEntityContainer));
                    })).ToArray <EntitySet>();
                }
            }
            else
            {
                name = somFunction.Namespace;
            }
            List <FunctionParameter> functionParameterList2 = new List <FunctionParameter>();

            foreach (Parameter parameter in somFunction.Parameters)
            {
                TypeUsage functionTypeUsage = Converter.GetFunctionTypeUsage(somFunction is ModelFunction, somFunction, (FacetEnabledSchemaElement)parameter, providerManifest, areConvertingForProviderManifest, parameter.Type, parameter.CollectionKind, parameter.IsRefType, convertedItemCache, newGlobalItems);
                if (functionTypeUsage == null)
                {
                    return((EdmFunction)null);
                }
                FunctionParameter functionParameter = new FunctionParameter(parameter.Name, functionTypeUsage, Converter.GetParameterMode(parameter.ParameterDirection));
                Converter.AddOtherContent((SchemaElement)parameter, (MetadataItem)functionParameter);
                if (parameter.Documentation != null)
                {
                    functionParameter.Documentation = Converter.ConvertToDocumentation(parameter.Documentation);
                }
                functionParameterList2.Add(functionParameter);
            }
            EdmFunction edmFunction = new EdmFunction(somFunction.Name, name, Converter.GetDataSpace(providerManifest), new EdmFunctionPayload()
            {
                Schema                 = somFunction.DbSchema,
                StoreFunctionName      = somFunction.StoreFunctionName,
                CommandText            = somFunction.CommandText,
                EntitySets             = (IList <EntitySet>)entitySetArray,
                IsAggregate            = new bool?(somFunction.IsAggregate),
                IsBuiltIn              = new bool?(somFunction.IsBuiltIn),
                IsNiladic              = new bool?(somFunction.IsNiladicFunction),
                IsComposable           = new bool?(somFunction.IsComposable),
                IsFromProviderManifest = new bool?(areConvertingForProviderManifest),
                IsFunctionImport       = new bool?(somFunction.IsFunctionImport),
                ReturnParameters       = (IList <FunctionParameter>)functionParameterList1.ToArray(),
                Parameters             = (IList <FunctionParameter>)functionParameterList2.ToArray(),
                ParameterTypeSemantics = new ParameterTypeSemantics?(somFunction.ParameterTypeSemantics)
            });

            if (!somFunction.IsFunctionImport)
            {
                newGlobalItems.Add((SchemaElement)somFunction, (GlobalItem)edmFunction);
            }
            if (somFunction.Documentation != null)
            {
                edmFunction.Documentation = Converter.ConvertToDocumentation(somFunction.Documentation);
            }
            Converter.AddOtherContent((SchemaElement)somFunction, (MetadataItem)edmFunction);
            return(edmFunction);
        }
 internal static EdmModel CreateConceptualModel(
     EntityContainer entityContainer,
     double schemaVersion = 3.0)
 {
     return(new EdmModel(entityContainer, schemaVersion));
 }
 private EdmModel(EntityContainer entityContainer, double version = 3.0)
 {
     this._container    = entityContainer;
     this.SchemaVersion = version;
 }
        // This collection allows changes to be intercepted before and after they are passed to MetadataCollection.  The interception
        // is required to update the EntitySet's back-reference to the EntityContainer.

        /// <summary>
        ///     Default constructor for constructing an empty collection
        /// </summary>
        /// <param name="entityContainer"> The entity container that has this entity set collection </param>
        /// <exception cref="System.ArgumentNullException">Thrown if the argument entityContainer is null</exception>
        internal EntitySetBaseCollection(EntityContainer entityContainer)
            : this(entityContainer, null)
        {
        }
예제 #46
0
 /// <summary>
 ///     Returns an <see cref="T:System.Data.Entity.Core.Metadata.Edm.EntityContainer" /> object by using the specified entity container name. If there is no entity container, the output parameter contains null; otherwise, it contains the first entity container.
 /// </summary>
 /// <returns>true if there is an entity container that matches the search criteria; otherwise, false.</returns>
 /// <param name="name">The name of the entity container.</param>
 /// <param name="entityContainer">
 ///     When this method returns, it contains an <see cref="T:System.Data.Entity.Core.Metadata.Edm.EntityContainer" /> object. If there is no entity container, this output parameter contains null; otherwise, it contains the first entity container.
 /// </param>
 public bool TryGetEntityContainer(string name, out EntityContainer entityContainer)
 {
     Check.NotNull(name, "name");
     return(TryGetEntityContainer(name, false /*ignoreCase*/, out entityContainer));
 }
 /// <summary>
 ///     The constructor for constructing the collection with the given items
 /// </summary>
 /// <param name="entityContainer"> The entity container that has this entity set collection </param>
 /// <param name="items"> The items to populate the collection </param>
 /// <exception cref="System.ArgumentNullException">Thrown if the argument entityContainer is null</exception>
 internal EntitySetBaseCollection(EntityContainer entityContainer, IEnumerable <EntitySetBase> items)
     : base(items)
 {
     Check.NotNull(entityContainer, "entityContainer");
     _entityContainer = entityContainer;
 }