/// <summary>
        /// Add default EntityContainer to the given EntitySchemaModel
        ///   For each base entity type, add an EntitySet
        ///   For each association, add an AssociationSet, between two possible EntitySets
        /// </summary>
        /// <param name="model">the given EntitySchemaModel</param>
        public void Fixup(EntityModelSchema model)
        {
            EntityContainer container = model.EntityContainers.FirstOrDefault();
            if (container == null)
            {
                container = new EntityContainer(this.DefaultContainerName);
                model.Add(container);
            }

            foreach (EntityType entity in model.EntityTypes.Where(e => e.BaseType == null && !container.EntitySets.Any(set => set.EntityType == e)))
            {
                if (!entity.Annotations.OfType<FixupNoSetAnnotation>().Any())
                {
                    container.Add(new EntitySet(entity.Name, entity));
                }
            }

            foreach (AssociationType association in model.Associations.Where(assoc => !container.AssociationSets.Any(assocSet => assocSet.AssociationType == assoc)))
            {
                if (!association.Annotations.OfType<FixupNoSetAnnotation>().Any())
                {
                    container.Add(new AssociationSet(association.Name, association)
                    {
                        Ends =
                            {
                                new AssociationSetEnd(association.Ends[0], container.EntitySets.First(es => association.Ends[0].EntityType.IsKindOf(es.EntityType))),
                                new AssociationSetEnd(association.Ends[1], container.EntitySets.First(es => association.Ends[1].EntityType.IsKindOf(es.EntityType))),
                            }
                    });
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the FunctionSegment class
 /// </summary>
 /// <param name="function">the function representing the Function</param>
 /// <param name="container">the entity container for the function</param>
 /// <param name="useParentheses">used to determine if the uri generated will have parentheses</param>
 internal FunctionSegment(Function function, EntityContainer container, bool useParentheses)
     : base()
 {
     ExceptionUtilities.CheckArgumentNotNull(function, "function");
     this.Container = container;
     this.Function = function;
     this.UseParentheses = useParentheses;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntitySetAndTypeSelector"/> class.
        /// </summary>
        /// <param name="entityContainer">The entity container.</param>
        /// <param name="random">The random number generator.</param>
        /// <param name="minimumNumberOfEntitiesPerEntitySet">The minimum number of entities per entity set.</param>
        public EntitySetAndTypeSelector(
            EntityContainer entityContainer,
            IRandomNumberGenerator random,
            int minimumNumberOfEntitiesPerEntitySet)
        {
            this.entityContainer = entityContainer;
            this.random = random;

            this.InitializeTargets(minimumNumberOfEntitiesPerEntitySet);
        }
        private Dictionary<EntitySet, Table> ConvertEntitySetsToTables(DatabaseSchema schema, EntityContainer container)
        {
            Dictionary<EntitySet, Table> entitySetToTableMapping = new Dictionary<EntitySet, Table>();

            foreach (EntitySet entitySet in container.EntitySets)
            {
                Table table = new Table(container.Name, entitySet.Name);
                schema.Tables.Add(table);
                entitySetToTableMapping.Add(entitySet, table);
                var type = entitySet.EntityType;
                var pk = new PrimaryKey("PK_" + table.Name);
                Dictionary<MemberProperty, Column> propertyToColumnMap = new Dictionary<MemberProperty, Column>();
                foreach (MemberProperty prop in type.Properties)
                {
                    var column = this.ConvertPropertyToColumn(prop);
                    propertyToColumnMap.Add(prop, column);

                    if (prop.IsPrimaryKey)
                    {
                        pk.Columns.Add(column);
                    }

                    table.Columns.Add(column);
                }

                if (pk.Columns.Count > 0)
                {
                    table.PrimaryKey = pk;
                }

                foreach (EdmUniqueConstraint edmUniqueConstraint in type.EdmUniqueConstraints)
                {
                    var uniqueConstraint = new UniqueConstraint("UC_" + table.Name + "_" + edmUniqueConstraint.Name);
                    foreach (var prop in edmUniqueConstraint.Properties)
                    {
                        Column column;
                        ExceptionUtilities.Assert(propertyToColumnMap.TryGetValue(prop, out column), "Edm Unique Constraint's property '{0}' is not found on entity type '{1}'.", prop.Name, type.FullName);
                        uniqueConstraint.Add(column);
                    }

                    table.Add(uniqueConstraint);
                }
            }

            return entitySetToTableMapping;
        }
 private IEnumerable<XElement> GenerateAssociationSets(EntityContainer container, XNamespace xmlNamespace)
 {
     var content = from set in container.AssociationSets
                   select this.GenerateAssociationSet(xmlNamespace, set);
     return content;
 }
        private EntityContainer ConvertToTaupoEntityContainer(IEdmEntityContainer edmEntityContainer)
        {
            var taupoEntityContainer = new EntityContainer(edmEntityContainer.Name);

            foreach (var edmEntitySet in edmEntityContainer.Elements.OfType<IEdmEntitySet>())
            {
                EntitySet taupoEntitySet = this.ConvertToTaupoEntitySet(edmEntitySet);
                taupoEntityContainer.Add(taupoEntitySet);

                foreach (var edmNavigationProperty in edmEntitySet.NavigationPropertyBindings.Select(t => t.NavigationProperty))
                {
                    if (!this.associationRegistry.IsAssociationSetRegistered(edmEntitySet, edmNavigationProperty))
                    {
                        this.associationRegistry.RegisterAssociationSet(edmEntitySet, edmNavigationProperty);
                    }
                }
            }

            foreach (var edmFunctionImport in edmEntityContainer.Elements.OfType<IEdmOperationImport>())
            {
                FunctionImport taupoFunctionImport = this.ConvertToTaupoFunctionImport(edmFunctionImport);
                taupoEntityContainer.Add(taupoFunctionImport);
            }

            this.ConvertAnnotationsIntoTaupo(edmEntityContainer, taupoEntityContainer);
            return taupoEntityContainer;
        }
Exemplo n.º 7
0
        public static IEdmModel BuildTestMetadata(IEntityModelPrimitiveTypeResolver primitiveTypeResolver, IDataServiceProviderFactory provider)
        {
            var schema = new EntityModelSchema()
            {
                new ComplexType("TestNS","Address")
                {
                    new MemberProperty("City", DataTypes.String.Nullable()), 
                    new MemberProperty("Zip", DataTypes.Integer),
                    new ClrTypeAnnotation(typeof(Address))
                },
                new EntityType("TestNS","Customer")
                {
                    new MemberProperty("ID", DataTypes.Integer){IsPrimaryKey=true},
                    new MemberProperty("Name", DataTypes.String.Nullable()),
                    new MemberProperty("Emails", DataTypes.CollectionType.WithElementDataType(DataTypes.String.Nullable())),
                    new MemberProperty("Address", DataTypes.ComplexType.WithName("TestNS","Address")),
                    new ClrTypeAnnotation(typeof(Customer))
                },
                new EntityType("TestNS","MultiKey")
                {
                    new MemberProperty("KeyB", DataTypes.FloatingPoint){IsPrimaryKey=true},
                    new MemberProperty("KeyA", DataTypes.String.Nullable()){IsPrimaryKey=true},
                    new MemberProperty("Keya", DataTypes.Integer){IsPrimaryKey=true},
                    new MemberProperty("NonKey", DataTypes.String.Nullable()),
                    new ClrTypeAnnotation(typeof(MultiKey))
                },
                new EntityType("TestNS","TypeWithPrimitiveProperties")
                {
                      new MemberProperty("ID", DataTypes.Integer){ IsPrimaryKey=true},
                      new MemberProperty("StringProperty", DataTypes.String.Nullable()),
                      new MemberProperty("BoolProperty", DataTypes.Boolean),
                      new MemberProperty("NullableBoolProperty", DataTypes.Boolean.Nullable()),
                      new MemberProperty("ByteProperty", EdmDataTypes.Byte),
                      new MemberProperty("NullableByteProperty",  EdmDataTypes.Byte.Nullable()),
                      new MemberProperty("DateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true)),
                      new MemberProperty("NullableDateTimeProperty", DataTypes.DateTime.WithTimeZoneOffset(true).Nullable()),
                      new MemberProperty("DecimalProperty", EdmDataTypes.Decimal()),
                      new MemberProperty("NullableDecimalProperty", EdmDataTypes.Decimal().Nullable()),
                      new MemberProperty("DoubleProperty", EdmDataTypes.Double),
                      new MemberProperty("NullableDoubleProperty", EdmDataTypes.Double.Nullable()),
                      new MemberProperty("GuidProperty", DataTypes.Guid),
                      new MemberProperty("NullableGuidProperty", DataTypes.Guid.Nullable()),
                      new MemberProperty("Int16Property", EdmDataTypes.Int16),
                      new MemberProperty("NullableInt16Property", EdmDataTypes.Int16.Nullable()),
                      new MemberProperty("Int32Property", DataTypes.Integer),
                      new MemberProperty("NullableInt32Property", DataTypes.Integer.Nullable()),
                      new MemberProperty("Int64Property", EdmDataTypes.Int64),
                      new MemberProperty("NullableInt64Property", EdmDataTypes.Int64.Nullable()),
                      new MemberProperty("SByteProperty", EdmDataTypes.SByte),
                      new MemberProperty("NullableSByteProperty", EdmDataTypes.SByte.Nullable()),
                      new MemberProperty("SingleProperty", EdmDataTypes.Single),
                      new MemberProperty("NullableSingleProperty", EdmDataTypes.Single.Nullable()),
                      new MemberProperty("BinaryProperty", DataTypes.Binary.Nullable()),
                      new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties))
                }
            };

            List<FunctionParameter> defaultParameters = new List<FunctionParameter>()
            {
                new FunctionParameter("soParam", DataTypes.Integer) 
            };

            EntitySet customersSet = new EntitySet("Customers", "Customer");
            EntityContainer container = new EntityContainer("BinderTestMetadata")
            {
                customersSet,
                new EntitySet("MultiKeys", "MultiKey"),
                new EntitySet("TypesWithPrimitiveProperties","TypeWithPrimitiveProperties")
            };
            schema.Add(container);

            EntityDataType customerType = DataTypes.EntityType.WithName("TestNS", "Customer");
            EntityDataType multiKeyType = DataTypes.EntityType.WithName("TestNS", "MultiKey");
            EntityDataType entityTypeWithPrimitiveProperties = DataTypes.EntityType.WithName("TestNS", "TypeWithPrimitiveProperties");

            ComplexDataType addressType = DataTypes.ComplexType.WithName("TestNS", "Address");

            addressType.Definition.Add(new ClrTypeAnnotation(typeof(Address)));
            customerType.Definition.Add(new ClrTypeAnnotation(typeof(Customer)));
            multiKeyType.Definition.Add(new ClrTypeAnnotation(typeof(MultiKey)));
            entityTypeWithPrimitiveProperties.Definition.Add(new ClrTypeAnnotation(typeof(TypeWithPrimitiveProperties)));

            //container.Add(CreateServiceOperation("VoidServiceOperation", defaultParameters, null, ODataServiceOperationResultKind.Void));
            //container.Add(CreateServiceOperation("DirectValuePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.DirectValue));
            //container.Add(CreateServiceOperation("DirectValueEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.DirectValue));

            //container.Add(CreateServiceOperation("EnumerationPrimitiveServiceOperation", defaultParameters, DataTypes.CollectionType.WithElementDataType(DataTypes.Integer), ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.Enumeration));
            //container.Add(CreateServiceOperation("EnumerationEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.Enumeration));

            //container.Add(CreateServiceOperation("QuerySinglePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithSingleResult));
            //container.Add(CreateServiceOperation("QuerySingleEntityServiceOperation", defaultParameters, customerType, customersSet, ODataServiceOperationResultKind.QueryWithSingleResult));

            //container.Add(CreateServiceOperation("QueryMultiplePrimitiveServiceOperation", defaultParameters, DataTypes.Integer, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleComplexServiceOperation", defaultParameters, addressType, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation("QueryMultipleEntityServiceOperation", defaultParameters, DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));

            //container.Add(CreateServiceOperation("ServiceOperationWithNoParameters", new List<FunctionParameter>(), DataTypes.CollectionOfEntities(customerType.Definition), customersSet, ODataServiceOperationResultKind.QueryWithMultipleResults));
            //container.Add(CreateServiceOperation(
            //                        "ServiceOperationWithMultipleParameters",
            //                         new List<FunctionParameter>()
            //                         {
            //                             new FunctionParameter("paramInt", DataTypes.Integer),  
            //                             new FunctionParameter("paramString", DataTypes.String.Nullable()),
            //                             new FunctionParameter("paramNullableBool", DataTypes.Boolean.Nullable()) 
            //                         },
            //                         DataTypes.CollectionOfEntities(customerType.Definition),
            //                         customersSet,
            //                         ODataServiceOperationResultKind.QueryWithMultipleResults));

            new ApplyDefaultNamespaceFixup("TestNS").Fixup(schema);
            new ResolveReferencesFixup().Fixup(schema);
            primitiveTypeResolver.ResolveProviderTypes(schema, new EdmDataTypeResolver());

            return provider.CreateMetadataProvider(schema);
        }
        private void CreateStubEntityTypes(QueryTypeLibrary library, EntityContainer container)
        {
            foreach (var entitySet in container.EntitySets)
            {
                var rootType = entitySet.EntityType;
                var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType));

                foreach (var entityType in allDerivedTypes)
                {
                    QueryEntityType stub = this.CreateStubEntityType(entityType, entitySet);
                    library.SetQueryEntityType(entitySet, entityType, stub);
                }

                // set up Parent for each type
                foreach (var childType in allDerivedTypes.Where(et => et != rootType))
                {
                    library.GetQueryEntityType(entitySet, childType).Parent = library.GetQueryEntityType(entitySet, childType.BaseType);
                }
            }

            // TODO: maybe this is wrong if >1 containers! Add unit test and fix.
            // construct DerivedTypes for each type
            foreach (var type in library.GetQueryEntityTypes())
            {
                for (var parent = type.Parent; parent != null; parent = parent.Parent)
                {
                    parent.DerivedTypes.Add(type);
                }
            }
        }
Exemplo n.º 9
0
        private void CompareEntityContainer(EntityContainer expectedEntityContainer, EntityContainer actualEntityContainer)
        {
            this.SatisfiesEquals(
                expectedEntityContainer.EntitySets.Count(),
                actualEntityContainer.EntitySets.Count(),
                "Count of EntitySets does not match for '{0}'.",
                expectedEntityContainer.Name);
            foreach (EntitySet expectedEntitySet in expectedEntityContainer.EntitySets)
            {
                var actualEntitySets = actualEntityContainer.EntitySets.Where(es => es.Name == expectedEntitySet.Name);
                if (this.SatisfiesEquals(1, actualEntitySets.Count(), "Should find exactly 1 entitySet '{0}'", expectedEntitySet.Name))
                {
                    var actualEntitySet = actualEntitySets.Single();
                    this.CompareEntitySet(expectedEntitySet, actualEntitySet);
                    this.CompareAnnotations(expectedEntitySet.Annotations, actualEntitySet.Annotations);
                }
            }

            this.SatisfiesEquals(
                expectedEntityContainer.AssociationSets.Count(),
                actualEntityContainer.AssociationSets.Count(),
                "Count of AssociationSets does not match for '{0}'.",
                expectedEntityContainer.Name);
            foreach (AssociationSet expectedAssociationSet in expectedEntityContainer.AssociationSets)
            {
                var actualAssociationSets = actualEntityContainer.AssociationSets.Where(asSet => asSet.Name == expectedAssociationSet.Name);
                if (this.SatisfiesEquals(1, actualAssociationSets.Count(), "Should find exactly 1 associationSet '{0}'", expectedAssociationSet.Name))
                {
                    var actualAssociationSet = actualAssociationSets.Single();
                    this.CompareAssociationSet(expectedAssociationSet, actualAssociationSet);
                    this.CompareAnnotations(expectedAssociationSet.Annotations, actualAssociationSet.Annotations);
                }
            }

            this.SatisfiesEquals(
                expectedEntityContainer.FunctionImports.Count(),
                actualEntityContainer.FunctionImports.Count(),
                "Count of FunctionImports does not match for '{0}'.",
                expectedEntityContainer.Name);
            foreach (FunctionImport expectedFunctionImport in expectedEntityContainer.FunctionImports)
            {
                var actualFunctionImports = actualEntityContainer.FunctionImports.Where(fi => this.FunctionImportSignaturesAreSame(fi, expectedFunctionImport));
                if (this.SatisfiesEquals(1, actualFunctionImports.Count(), "Should find exactly 1 FunctionImport '{0}'", expectedFunctionImport.Name))
                {
                    var actualFunctionImport = actualFunctionImports.Single();
                    this.CompareFunctionImport(expectedFunctionImport, actualFunctionImport);
                    this.CompareAnnotations(expectedFunctionImport.Annotations, actualFunctionImport.Annotations);
                }
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Removes an <see cref="EntityContainer"/> from the model.
 /// </summary>
 /// <param name="entityContainer">Container to be removed.</param>
 public void Remove(EntityContainer entityContainer)
 {
     ExceptionUtilities.CheckArgumentNotNull(entityContainer, "entityContainer");
     ExceptionUtilities.Assert(entityContainer.Model == this, "Entity container was not added to this model");
     ExceptionUtilities.Assert(this.entityContainersList.Remove(entityContainer), "Entity container was not added to this model");
     entityContainer.Model = null;
 }
        private void CreateNavigationMembers(QueryTypeLibrary library, QueryEntityType result, IEnumerable<NavigationProperty> navigationProperties, EntityContainer container)
        {
            foreach (var navprop in navigationProperties)
            {
                // handle MEST scenario where there are multiple association sets corresponding to a navigation property
                var asets = container.AssociationSets.Where(c => c.AssociationType == navprop.Association);
                var aset = asets.Single(set => set.Ends.Any(end => end.AssociationEnd == navprop.FromAssociationEnd && end.EntitySet == result.EntitySet));

                var toSet = aset.Ends.Single(e => e.AssociationEnd == navprop.ToAssociationEnd).EntitySet;
                var targetEntityType = library.GetQueryEntityType(toSet, navprop.ToAssociationEnd.EntityType);

                QueryProperty property;

                if (navprop.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
                {
                    // collection property
                    property = QueryProperty.Create(navprop.Name, targetEntityType.CreateCollectionType());
                }
                else
                {
                    // reference property
                    property = QueryProperty.Create(navprop.Name, targetEntityType);
                }

                result.Add(property);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Assesses all the associations in the specified <see cref="EntityContainer"/>
        /// and returns an abstraction that facilitates access to association and association
        /// end data, including navigation properties, relationship metadata, and dependent/principal
        /// information.
        /// </summary>
        /// <param name="entityContainer">The <see cref="EntityContainer"/> from which to determine relationships.</param>
        /// <returns>A collection of <see cref="RelationshipType"/>s that can be further queried
        /// to meet the consumer's needs.</returns>
        public static IEnumerable <RelationshipType> RelationshipTypes(this EntityContainer entityContainer)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityContainer, "entityContainer");

            return(entityContainer.AssociationSets.Select(a => a.RelationshipType()));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Generates EntityContainer element from <see cref="EntityContainer"/>
 /// </summary>
 /// <param name="xmlNamespace">XML namespace to use</param>
 /// <param name="container">Entity container</param>
 /// <returns>'EntityContainer' <see cref="XElement"/></returns>
 protected override XElement GenerateEntityContainer(XNamespace xmlNamespace, EntityContainer container)
 {
     var element = base.GenerateEntityContainer(xmlNamespace, container);
     TypeAccessModifierAnnotation annotation = container.Annotations.OfType<TypeAccessModifierAnnotation>().SingleOrDefault();
     element.Add(GenerateTypeAccessModifier(annotation));
     return element;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Constructs service operation segment
 /// </summary>
 /// <param name="function">The function representing the service operation</param>
 /// <param name="container">The container for the function</param>
 /// <param name="useParentheses">used to determine if the uri generated will have parentheses</param>
 /// <returns>A service operations segment</returns>
 public static ODataUriSegment ServiceOperation(Function function, EntityContainer container, bool useParentheses)
 {
     ExceptionUtilities.CheckArgumentNotNull(function, "function");
     return new FunctionSegment(function, container, useParentheses);
 }
Exemplo n.º 15
0
        private void CloneContainerContents(EntityContainer baseContainer, EntityContainer extendedContainer)
        {
            foreach (var entitySet in baseContainer.EntitySets)
            {
                var clonedEntitySet = new EntitySet(entitySet.Name, entitySet.EntityType);
                extendedContainer.Add(clonedEntitySet);
            }

            foreach (var associationSet in baseContainer.AssociationSets)
            {
                var clonedAssociationSet = new AssociationSet(associationSet.Name, associationSet.AssociationType);
                foreach (var setEnd in associationSet.Ends)
                {
                    clonedAssociationSet.Add(new AssociationSetEnd(setEnd.AssociationEnd, setEnd.EntitySet.Name));
                }

                extendedContainer.Add(clonedAssociationSet);
            }

            foreach (var functionImport in baseContainer.FunctionImports)
            {
                var clonedFunctionImport = new FunctionImport(functionImport.Name);
                foreach (var returnType in functionImport.ReturnTypes)
                {
                    clonedFunctionImport.ReturnTypes.Add(returnType);
                }

                foreach (var parameter in functionImport.Parameters)
                {
                    clonedFunctionImport.Add(new FunctionParameter(parameter.Name, parameter.DataType, parameter.Mode));
                }

                extendedContainer.Add(clonedFunctionImport);
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Constructs service operation segment
 /// </summary>
 /// <param name="function">The function representing the service operation</param>
 /// <param name="container">The container for the function</param>
 /// <returns>A service operations segment</returns>
 public static ODataUriSegment ServiceOperation(Function function, EntityContainer container)
 {
     return ServiceOperation(function, container, false);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Visits entity container
        /// </summary>
        /// <param name="container">entity container to visit</param>
        protected virtual void VisitEntityContainer(EntityContainer container)
        {
            this.VisitAnnotatedItem(container);

            foreach (var entitySet in container.EntitySets)
            {
                this.VisitEntitySet(entitySet);
            }

            foreach (var associationSet in container.AssociationSets)
            {
                this.VisitAssociationSet(associationSet);
            }

            foreach (var functionImport in container.FunctionImports)
            {
                this.VisitFunctionImport(functionImport);
            }
        }
 /// <summary>
 /// Initializes a new instance of the PathToProperty class.
 /// </summary>
 /// <param name="container">The entity container</param>
 /// <param name="entitySet">The entity set</param>
 /// <param name="entityType">The entity type</param>
 public PathToProperty(EntityContainer container, EntitySet entitySet, EntityType entityType)
 {
     this.Container = container;
     this.EntitySet = entitySet;
     this.EntityType = entityType;
     this.PathStackWithinEntityType = new List<string>();
 }
Exemplo n.º 19
0
        protected EntityContainer AddContainer(EntityModelSchema schema, string namespaceName)
        {
            EntityContainer container = new EntityContainer("TestContainer");
            schema.Add(container);
            new ApplyDefaultNamespaceFixup(namespaceName).Fixup(schema);
            new ResolveReferencesFixup().Fixup(schema);
            this.PrimitiveTypeResolver.ResolveProviderTypes(schema, this.EdmDataTypeResolver);

            return container;
        }
Exemplo n.º 20
0
 private IEnumerable<XElement> GenerateFunctionImports(EntityContainer container, XNamespace xmlNamespace)
 {
     var content = from f in container.FunctionImports
                   select this.GenerateFunctionImport(xmlNamespace, f);
     return content;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Adds new <see cref="EntityContainer"/> to the model.
 /// </summary>
 /// <param name="entityContainer">Container to be added.</param>
 public void Add(EntityContainer entityContainer)
 {
     ExceptionUtilities.CheckArgumentNotNull(entityContainer, "entityContainer");
     ExceptionUtilities.Assert(entityContainer.Model == null, "Entity container was already added to another model");
     entityContainer.Model = this;
     this.entityContainersList.Add(entityContainer);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Generates the additional entity container items.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <param name="xmlNamespace">The XML namespace.</param>
 /// <returns>Empty sequence, can be overridden in derived classes.</returns>
 protected virtual IEnumerable<XObject> GenerateAdditionalEntityContainerItems(EntityContainer container, XNamespace xmlNamespace)
 {
     return Enumerable.Empty<XObject>();
 }
Exemplo n.º 23
0
        /// <summary>
        /// Parses an entity container element in the csdl/ssdl file.
        /// </summary>
        /// <param name="entityContainerElement">the entity container element to parse</param>
        /// <returns>the parsed entity container object in the entity model schema</returns>
        protected virtual EntityContainer ParseEntityContainer(XElement entityContainerElement)
        {
            string name = entityContainerElement.GetRequiredAttributeValue("Name");
            var entityContainer = new EntityContainer(name);
            foreach (var entitySetElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "EntitySet")))
            {
                entityContainer.Add(this.ParseEntitySet(entitySetElement));
            }

            foreach (var entitySetElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "AssociationSet")))
            {
                entityContainer.Add(this.ParseAssociationSet(entitySetElement));
            }

            this.ParseAnnotations(entityContainer, entityContainerElement);
            return entityContainer;
        }
        private void BuildStructuralTypes(QueryTypeLibrary library, EntityContainer container)
        {
            foreach (var entitySet in container.EntitySets)
            {
                var rootType = entitySet.EntityType;
                var allDerivedTypes = container.Model.EntityTypes.Where(et => et.IsKindOf(rootType));

                foreach (var entityType in allDerivedTypes)
                {
                    var queryEntityType = library.GetQueryEntityType(entitySet, entityType);

                    var pathToProperty = new PathToProperty(container, entitySet, entityType);
                    this.CreateMembers(library, queryEntityType, entityType.AllProperties, pathToProperty);
                    ExceptionUtilities.Assert(pathToProperty.PathStackWithinEntityType.Count == 0, "Path to property stack is not empty.");

                    this.CreateNavigationMembers(library, queryEntityType, entityType.AllNavigationProperties, container);
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Generates addition items in entity container specific to csdl (e.g. FunctionImport)
 /// </summary>
 /// <param name="container">the container</param>
 /// <param name="xmlNamespace">the xml namespace</param>
 /// <returns>some XElements or XAttributes for items specific to csdl</returns>
 protected override IEnumerable<XObject> GenerateAdditionalEntityContainerItems(EntityContainer container, XNamespace xmlNamespace)
 {
     return this.GenerateFunctionImports(container, xmlNamespace).Cast<XObject>();
 }
        private void ConvertAssociationSetsToForeignKeys(EntityContainer container, Dictionary<EntitySet, Table> entitySetToTable)
        {
            foreach (AssociationSet associationSet in container.AssociationSets)
            {
                var assoc = associationSet.AssociationType;
                var referentialConstraint = assoc.ReferentialConstraint;

                ExceptionUtilities.Assert(referentialConstraint != null, "S-space associations must have RI constraints");

                var dependentSet = associationSet.Ends.Single(c => c.AssociationEnd == referentialConstraint.DependentAssociationEnd).EntitySet;
                var principalSet = associationSet.Ends.Single(c => c.AssociationEnd == referentialConstraint.PrincipalAssociationEnd).EntitySet;

                var principalTable = entitySetToTable[principalSet];
                var dependentTable = entitySetToTable[dependentSet];
                var fk = new ForeignKey(container.Name, associationSet.Name);
                fk.Target = principalTable;
                fk.Schema = dependentTable.Schema;
                foreach (var prop in referentialConstraint.DependentProperties)
                {
                    var dependentColumn = dependentTable.Columns.Single(c => c.Name == prop.Name);
                    fk.SourceColumns.Add(dependentColumn);
                }

                foreach (var prop in referentialConstraint.PrincipalProperties)
                {
                    var principalColumn = principalTable.Columns.Single(c => c.Name == prop.Name);
                    fk.TargetColumns.Add(principalColumn);
                }

                dependentTable.ForeignKeys.Add(fk);
            }
        }
Exemplo n.º 27
0
        private void CompareEntityContainer(EntityContainer expectedEntityContainer, EntityContainer actualEntityContainer)
        {
            foreach (EntitySet expectedEntitySet in expectedEntityContainer.EntitySets)
            {
                List<EntitySet> entitySets = actualEntityContainer.EntitySets.Where(es => es.Name == expectedEntitySet.Name).ToList();
                if (!this.WriteErrorIfFalse(entitySets.Count == 1, "Cannot find entitySet '{0}'", expectedEntitySet.Name))
                {
                    EntitySet yentitySet = entitySets.Single();
                    this.CompareEntitySet(expectedEntitySet, yentitySet);
                }
            }

            foreach (AssociationSet expectedAssociationSet in expectedEntityContainer.AssociationSets)
            {
                List<AssociationSet> associationSets = actualEntityContainer.AssociationSets.Where(asSet => asSet.Name == expectedAssociationSet.Name).ToList();
                if (!this.WriteErrorIfFalse(associationSets.Count == 1, "Cannot find associationSet '{0}'", expectedAssociationSet.Name))
                {
                    AssociationSet actualassociationSet = associationSets.Single();
                    this.CompareAssociationSet(expectedAssociationSet, actualassociationSet);
                }
            }

            foreach (FunctionImport expectedFunctionImport in expectedEntityContainer.FunctionImports)
            {
                List<FunctionImport> functionImports = actualEntityContainer.FunctionImports.Where(fi => fi.Name == expectedFunctionImport.Name && fi.Parameters.Count() == expectedFunctionImport.Parameters.Count()).ToList();
                if (!this.WriteErrorIfFalse(functionImports.Count == 1, "Cannot find FunctionImport '{0}'", expectedFunctionImport.Name))
                {
                    FunctionImport actualFunctionImport = functionImports.Single();
                    this.CompareFunctionImport(expectedFunctionImport, actualFunctionImport);
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Generates EntityContainer element from <see cref="EntityContainer"/>
 /// </summary>
 /// <param name="xmlNamespace">XML namespace to use</param>
 /// <param name="container">Entity container</param>
 /// <returns>'EntityContainer' <see cref="XElement"/></returns>
 protected virtual XElement GenerateEntityContainer(XNamespace xmlNamespace, EntityContainer container)
 {
     return new XElement(
         xmlNamespace + "EntityContainer",
         (container.Name != null ? new XAttribute("Name", container.Name) : null),
         this.GenerateDocumentation(xmlNamespace, container),
         this.GenerateEntitySets(container, xmlNamespace),
         this.GenerateAssociationSets(container, xmlNamespace),
         this.GenerateAdditionalEntityContainerItems(container, xmlNamespace),
         this.GenerateAnnotations(xmlNamespace, container));
 }