コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the StoreFunctionBodyGenerationInfoAnnotation class.
        /// </summary>
        /// <param name="sourceEntitySet">Store EntitySet (table) that is the source of the table-valued function.</param>
        /// <param name="resultTypesToFilter">List of entity types that should be filtered from the result.</param>
        /// <param name="discriminatorColumnName">Name of the discriminator column.</param>
        public StoreFunctionBodyGenerationInfoAnnotation(EntitySet sourceEntitySet, IEnumerable<string> resultTypesToFilter, string discriminatorColumnName)
        {
            ExceptionUtilities.CheckArgumentNotNull(sourceEntitySet, "sourceEntitySet");

            this.SourceEntitySet = sourceEntitySet;
            this.ResultTypesToFilterOut = resultTypesToFilter.ToList().AsReadOnly();
            this.DiscriminatorColumnName = discriminatorColumnName;
        }
コード例 #2
0
        /// <summary>
        /// Generates the conventional stream edit link for the given entity: http://serviceRoot/SetName(keyValues)/$value
        /// </summary>
        /// <param name="entitySet">The entity set of the entity</param>
        /// <param name="entityType">The type of the entity</param>
        /// <param name="keyValues">They values of the entity's key</param>
        /// <returns>The convention-based stream edit link</returns>
        public string GenerateDefaultStreamEditLink(EntitySet entitySet, EntityType entityType, IEnumerable<NamedValue> keyValues)
        {
            // null checks performed by this helper
            var uri = this.GenerateEntityEditLinkUri(entitySet, entityType, keyValues);

            uri.Segments.Add(SystemSegment.Value);

            return this.UriToStringConverter.ConvertToString(uri);
        }
コード例 #3
0
        /// <summary>
        /// Considers the candidate for this relationship.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="entityType">Type of the entity.</param>
        /// <param name="key">The entity data key of the candidate.</param>
        public void ConsiderCandidate(EntitySet entitySet, EntityType entityType, EntityDataKey key)
        {
            foreach (RelationshipGroupEnd end in this.ends.Where(e => e.EntitySet == entitySet && entityType.IsKindOf(e.EntityType)))
            {
                CapacityRange capacityRange = end.CapacitySelector();

                if (capacityRange != CapacityRange.Zero)
                {
                    this.RemoveCandidatesOnTargetBasedOnTreshhold(end);
                    
                    RelationshipCandidate candidate = new RelationshipCandidate(end, key, capacityRange);
                    end.Candidates.Add(candidate);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a default instance of a CLR object which represents the specified <paramref name="entityType"/> and <paramref name="entitySet"/>.
        /// </summary>
        /// <param name="objectServices">The object services.</param>
        /// <param name="entitySet">The <see cref="EntitySet"/> in which the <paramref name="entityType"/> resides.</param>
        /// <param name="entityType">The <see cref="EntityType"/> from which to create a CLR object.</param>
        /// <returns>A CLR object that maps to the <paramref name="entityType"/>.</returns>
        public static object CreateData(this IEntityModelObjectServices objectServices, EntitySet entitySet, EntityType entityType)
        {
            ExceptionUtilities.CheckArgumentNotNull(objectServices, "objectServices");
            ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");

            if (entityType.IsAbstract)
            {
                throw new TaupoArgumentException("Cannot create data for abstract entity type.");
            }

            var generator = objectServices.GetEntitySetObjectGenerator(entityType.FullName, entitySet.ContainerQualifiedName);
            var entity = generator.GenerateData().Data;
            return entity;
        }
コード例 #5
0
        /// <summary>
        /// Determines whether an entity set is expected to be returned from a function call
        /// </summary>
        /// <param name="function">the function being called</param>
        /// <param name="previousEntitySet">the binding entity set</param>
        /// <param name="returningEntitySet">the expected entity set, if appropriate</param>
        /// <returns>whether or not an entity set is expected</returns>
        public static bool TryGetExpectedActionEntitySet(this Function function, EntitySet previousEntitySet, out EntitySet returningEntitySet)
        {
            ExceptionUtilities.CheckArgumentNotNull(function, "function");

            ServiceOperationAnnotation serviceOperationAnnotation = function.Annotations.OfType<ServiceOperationAnnotation>().Single();
            EntityDataType entityDataType = function.ReturnType as EntityDataType;
            CollectionDataType collectionDataType = function.ReturnType as CollectionDataType;
            if (collectionDataType != null)
            {
                entityDataType = collectionDataType.ElementDataType as EntityDataType;
            }

            if (entityDataType != null)
            {
                if (serviceOperationAnnotation.EntitySetPath == null)
                {
                    returningEntitySet = function.Model.GetDefaultEntityContainer().EntitySets.Single(es => es.EntityType == entityDataType.Definition);
                }
                else
                {
                    string navigationPropertyName = serviceOperationAnnotation.EntitySetPath.Substring(serviceOperationAnnotation.EntitySetPath.LastIndexOf('/') + 1);
                    NavigationProperty navigationProperty = previousEntitySet.EntityType.AllNavigationProperties.Single(np => np.Name == navigationPropertyName);
                    var associationSets = function.Model.GetDefaultEntityContainer().AssociationSets.Where(a => a.AssociationType == navigationProperty.Association);
                    AssociationSet associationSet = associationSets.Single(a => a.Ends.Any(e => e.EntitySet == previousEntitySet));
                    returningEntitySet = associationSet.Ends.Single(es => es.EntitySet != previousEntitySet).EntitySet;
                }

                return true;
            }

            returningEntitySet = null;
            return false;
        }
コード例 #6
0
        /// <summary>
        /// Generates the conventional edit link for the given named stream: http://serviceRoot/SetName(keyValues)/StreamName
        /// </summary>
        /// <param name="entitySet">The entity set of the entity</param>
        /// <param name="entityType">The type of the entity</param>
        /// <param name="keyValues">They values of the entity's key</param>
        /// <param name="streamName">The stream's name</param>
        /// <returns>The convention-based stream edit link</returns>
        public string GenerateNamedStreamEditLink(EntitySet entitySet, EntityType entityType, IEnumerable<NamedValue> keyValues, string streamName)
        {
            // null checks performed by this helper
            var uri = this.GenerateEntityEditLinkUri(entitySet, entityType, keyValues);

            // null checks performed by ODataUriBuilder
            uri.Segments.Add(ODataUriBuilder.NamedStream(entityType, streamName));

            return this.UriToStringConverter.ConvertToString(uri);
        }
コード例 #7
0
 /// <summary>
 /// Adds an <see cref="EntitySet"/> to <see cref="EntitySets" /> collection.
 /// </summary>
 /// <param name="entitySet">Entity set to add.</param>
 public void Add(EntitySet entitySet)
 {
     ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");
     ExceptionUtilities.Assert(entitySet.Container == null, "Entity set was already added to another container");
     entitySet.Container = this;
     this.entitySetsList.Add(entitySet);
 }
コード例 #8
0
        /// <summary>
        /// Factory method to create the <see cref="QueryRootExpression"/> for the given entity set.
        /// </summary>
        /// <param name="entitySet">The underlying entity set for the root query.</param>
        /// <returns>The <see cref="QueryRootExpression"/> with the specified underlying entity set.</returns>
        public static QueryExpression Root(EntitySet entitySet)
        {
            ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");

            return new QueryRootExpression(entitySet, QueryType.Unresolved);
        }
コード例 #9
0
        private EntitySetDataRow PopulateNewEntitySetRow(EntityContainerData data, EntitySet entitySet, EntityType entityType)
        {
            var entityData = this.StructuralDataServices.GetStructuralGenerator(entityType.FullName, this.EntityContainer.Name + "." + entitySet.Name).GenerateData();

            return this.PopulateEntitySetRow(data, entitySet, entityType, entityData);
        }
コード例 #10
0
        /// <summary>
        /// Sets the minimum number of entities to be created for the specified entity set and type.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="entityType">The entity type.</param>
        /// <param name="count">The minimum number of entities to create.</param>
        public void SetMinimumNumberOfEntities(EntitySet entitySet, EntityType entityType, int count)
        {
            ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");

            this.SetMinimumNumberOfEntities(entitySet.Name, entityType.Name,  count);
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the AssociationSetEnd class.
 /// </summary>
 /// <param name="associationEnd">The association end.</param>
 /// <param name="entitySet">The entity set.</param>
 public AssociationSetEnd(AssociationEnd associationEnd, EntitySet entitySet)
 {
     this.EntitySet = entitySet;
     this.AssociationEnd = associationEnd;
 }
コード例 #12
0
 /// <summary>
 /// Increments count of entities for the specified entity set and type.
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="entityType">The entity type.</param>
 public void IncrementCount(EntitySet entitySet, EntityType entityType)
 {
     this.counters[entitySet.Name][entityType.Name].Increment();
 }
コード例 #13
0
        /// <summary>
        /// Tries to get next entity set and type to create.
        /// </summary>
        /// <param name="entitySet">The entity set.</param>
        /// <param name="entityType">The entity type.</param>
        /// <returns>True if there is a next entity set and type needs to be created, false otherwise.</returns>
        public bool TryGetNextEntitySetAndTypeToCreate(out EntitySet entitySet, out EntityType entityType)
        {
            entitySet = null;
            entityType = null;

            int maxCountRemaining = 0;
            List<Counter> farthestFromTarget = new List<Counter>();
            foreach (string entitySetName in this.counters.Keys)
            {
                this.FindFarthestFromTarget(entitySetName, ref maxCountRemaining, farthestFromTarget, null);
            }

            Counter counter = null;
            if (farthestFromTarget.Count != 0)
            {
                counter = this.random.ChooseFrom(farthestFromTarget);
                entitySet = counter.EntitySet;
                entityType = counter.EntityType;
            }

            return counter != null;
        }
コード例 #14
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);
        }
コード例 #15
0
        private EntitySet ConvertToTaupoEntitySet(IEdmEntitySet edmEntitySet)
        {
            var taupoEntitySet = new EntitySet(edmEntitySet.Name);
            taupoEntitySet.EntityType = new EntityTypeReference(edmEntitySet.EntityType().Namespace, edmEntitySet.EntityType().Name);

            this.ConvertAnnotationsIntoTaupo(edmEntitySet, taupoEntitySet);
            return taupoEntitySet;
        }
コード例 #16
0
 private void CompareEntitySet(EntitySet expectedEntitySet, EntitySet actualEntitySet)
 {
     this.SatisfiesEquals(expectedEntitySet.EntityType.FullName, actualEntitySet.EntityType.FullName, "EntitySet EntityType does not match.");
 }
コード例 #17
0
        private bool InitializeFunctionMetadata(Function function, EntitySet previousEntitySet, out EntitySet returningEntitySet)
        {
            // Push the function as the source of the response, and then
            // push further metadata describing the expected response, if appropriate
            this.MetadataStack.Push(function);

            EntitySet entitySet = null;
            bool foundExpectedEntitySet;
            ServiceOperationAnnotation serviceOperationAnnotation = function.Annotations.OfType<ServiceOperationAnnotation>().SingleOrDefault();
            if (serviceOperationAnnotation == null)
            {
                foundExpectedEntitySet = function.TryGetExpectedServiceOperationEntitySet(out entitySet);
            }
            else
            {
                foundExpectedEntitySet = function.TryGetExpectedActionEntitySet(previousEntitySet, out entitySet);
            }

            if (foundExpectedEntitySet)
            {
                this.MetadataStack.Push(entitySet);
                returningEntitySet = entitySet;
                return true;
            }

            if (function.ReturnType != null)
            {
                this.MetadataStack.Push(function.ReturnType);
            }

            returningEntitySet = null;
            return false;
        }
コード例 #18
0
ファイル: XsdlParserBase.cs プロジェクト: larsenjo/odata.net
 /// <summary>
 /// Parses the entity set
 /// </summary>
 /// <param name="entitySetElement">the entityset element to parse</param>
 /// <returns>the entityset presentation in the entity model schema</returns>
 protected virtual EntitySet ParseEntitySet(XElement entitySetElement)
 {
     string entitySetName = entitySetElement.GetRequiredAttributeValue("Name");
     string entityTypeNamespace = this.ParseEdmTypeName(entitySetElement.GetRequiredAttributeValue("EntityType"))[0];
     string entityTypeName = this.ParseEdmTypeName(entitySetElement.GetRequiredAttributeValue("EntityType"))[1];
     var entitySet = new EntitySet(entitySetName, new EntityTypeReference(entityTypeNamespace, entityTypeName));
     this.ParseAnnotations(entitySet, entitySetElement);
     return entitySet;
 }
コード例 #19
0
 private void CompareEntitySet(EntitySet expectedEntitySet, EntitySet actualEntitySet)
 {
     this.WriteErrorIfFalse(expectedEntitySet.EntityType.Name == actualEntitySet.EntityType.Name, "EntitySet EntityType property does not match Expected '{0}' Actual '{1}'", expectedEntitySet.EntityType, actualEntitySet.EntityType);
 }
コード例 #20
0
        private bool HasOverlappingNonNullableForeignKeys(EntitySet entitySet, EntityType entityType)
        {
            foreach (AssociationSet associationSet in this.entityContainer.AssociationSets
                .Where(s => s.AssociationType.ReferentialConstraint != null && entityType.IsKindOf(s.AssociationType.ReferentialConstraint.DependentAssociationEnd.EntityType)
                    && s.Ends.Where(e => e.AssociationEnd == s.AssociationType.ReferentialConstraint.DependentAssociationEnd).Single().EntitySet == entitySet))
            {
                foreach (MemberProperty dependentProperty in associationSet.AssociationType.ReferentialConstraint.DependentProperties.Where(p => !p.PropertyType.IsNullable))
                {
                    if (entitySet.Container.Model.Associations.Any(a => a.ReferentialConstraint != null &&
                            a != associationSet.AssociationType &&
                            a.ReferentialConstraint.DependentProperties.Contains(dependentProperty)))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #21
0
        /// <summary>
        /// Adds seed data to the <see cref="EntityContainerData"/> created by this instance by
        /// calling <see cref="TryPopulateNextData"/>.
        /// </summary>
        /// <param name="entitySet">The <see cref="EntitySet"/> to which the new seed instance belongs.</param>
        /// <param name="entityType">The <see cref="EntityType"/> of the new seed instance.</param>
        /// <param name="entityData">A collection of <see cref="NamedValue"/>s that describe the structural data of the instance.</param>
        /// <returns>The <see cref="EntityDataKey"/> that describes the seed instance.</returns>
        public EntityDataKey Seed(EntitySet entitySet, EntityType entityType, IEnumerable<NamedValue> entityData)
        {
            this.CreateEntitySetAndTypeSelectorIfNull();
            this.CreateRelationshipSelectorsIfNull();

            if (this.seedData == null)
            {
                this.seedData = new EntityContainerData(this.entityContainer);
            }

            var seedRow = this.PopulateEntitySetRow(this.seedData, entitySet, entityType, entityData);
            this.ConsiderCandidateForRelationships(seedRow);

            return seedRow.Key;
        }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Counter"/> class.
 /// </summary>
 /// <param name="entitySet">The entity set.</param>
 /// <param name="entityType">Type of the entity.</param>
 public Counter(EntitySet entitySet, EntityType entityType)
 {
     this.EntitySet = entitySet;
     this.EntityType = entityType;
 }
コード例 #23
0
        private bool GetNextEntitySetAndTypeToCreate(out EntitySet entitySet, out EntityType entityType)
        {
            if (this.entitiesToCreateInNextBatch.Count > 0)
            {
                var entitySetAndType = this.Random.ChooseFrom(this.entitiesToCreateInNextBatch);
                entitySet = entitySetAndType.Key;
                entityType = entitySetAndType.Value;

                return true;
            }
            else
            {
                return this.entitySetAndTypeSelector.TryGetNextEntitySetAndTypeToCreate(out entitySet, out entityType);
            }
        }
コード例 #24
0
 /// <summary>
 /// Returns a value indicating whether we should add a RootQuery for this entity set
 /// </summary>
 /// <param name="entitySet">The entity set to add a root query for</param>
 /// <returns>A value indicating whether we should add a RootQuery for this entity set</returns>
 protected virtual bool ShouldCreateRootQuery(EntitySet entitySet)
 {
     return true;
 }
コード例 #25
0
        private EntitySetDataRow PopulateEntitySetRow(EntityContainerData data, EntitySet entitySet, EntityType entityType, IEnumerable<NamedValue> entityData)
        {
            EntitySetDataRow row = data[entitySet].AddNewRowOfType(entityType);

            foreach (NamedValue namedValue in entityData)
            {
                row.SetValue(namedValue.Name, namedValue.Value);
            }

            this.entitySetAndTypeSelector.IncrementCount(entitySet, entityType);

            return row;
        }
コード例 #26
0
            private CodeExpression RewritePropertyReference(CodePropertyReferenceExpression propertyReference, ref bool didRewrite)
            {
                var targetRef = propertyReference.TargetObject as CodePropertyReferenceExpression;
                if (targetRef != null)
                {
                    //
                    // Replace this pattern :
                    //      context.entity
                    //
                    // With:
                    //      context.GetQueryRootForResourceSet(<entity reference name>).Cast<entity type>()
                    //
                    if (targetRef.PropertyName.Equals(DictionaryProviderServiceMethodResolver.ContextInstancePropertyName))
                    {
                        var entitySet = this.model.GetDefaultEntityContainer().EntitySets.SingleOrDefault(s => s.Name == propertyReference.PropertyName);
                        if (entitySet != null)
                        {
                            this.rootEntitySet = entitySet;

                            var setLambda = Code.Lambda().WithParameter("s").WithBody(Code.Argument("s").Property("Name").Equal(Code.Primitive(entitySet.Name), DataTypes.String));
                            var setReference = Code.This().Property(DictionaryProviderServiceMethodResolver.ContextInstancePropertyName).Property(ResourceSetsPropertyName).Call("Single", setLambda);
                            var setBaseTypeReference = this.GetClrTypeReference(entitySet.EntityType);

                            didRewrite = true;
                            return targetRef.Call(RootQueryMethodName, setReference).Call("Cast", new CodeTypeReference[] { setBaseTypeReference });
                        }
                    }
                }
                else if (propertyReference.TargetObject is CodeArgumentReferenceExpression)
                {
                    if (this.rootEntitySet != null)
                    {
                        // TODO: more derived types?
                        var entityType = this.rootEntitySet.EntityType;
                        var property = entityType.AllProperties.Where(p => p.Name == propertyReference.PropertyName && !p.IsTypeBacked()).SingleOrDefault();
                        if (property != null)
                        {
                            //
                            // Replace this pattern:
                            //      arg.EntityProperty    
                            // With:
                            //      (<property type>)arg[<PropertyName>]
                            //
                            var propertyType = property.PropertyType;

                            CodeTypeReference propertyTypeRef = Code.TypeRef(typeof(object));
                            if (propertyType != null)
                            {
                                var primitivePropertyType = propertyType as PrimitiveDataType;
                                if (primitivePropertyType != null)
                                {
                                    var clrType = primitivePropertyType.GetFacetValue<PrimitiveClrTypeFacet, Type>(typeof(object));

                                    // We need to make sure we have the right primitive type for the cast below. 
                                    // If its a nullable property, then the CLR type we cast to must be nullable as well
                                    bool clrTypeIsNullable = clrType.IsClass() || Nullable.GetUnderlyingType(clrType) != null;
                                    if (primitivePropertyType.IsNullable && !clrTypeIsNullable)
                                    {
                                        clrType = typeof(Nullable<>).MakeGenericType(clrType);
                                    }

                                    propertyTypeRef = Code.TypeRef(clrType);
                                }

                                var complexPropertyType = propertyType as ComplexDataType;
                                if (complexPropertyType != null)
                                {
                                    propertyTypeRef = this.GetClrTypeReference(complexPropertyType.Definition);
                                }
                            }

                            didRewrite = true;
                            return propertyReference.TargetObject.Index(Code.Primitive(propertyReference.PropertyName)).Cast(propertyTypeRef);
                        }
                    }
                }

                return base.Rewrite(propertyReference, ref didRewrite);
            }
コード例 #27
0
 /// <summary>
 /// Initializes a new instance of the FunctionImportReturnType class with the given return type and entity set.
 /// </summary>
 /// <param name="returnType">The return type for the FunctionImport</param>
 /// <param name="entitySet">The entity set associated with the return type</param>
 public FunctionImportReturnType(DataType returnType, EntitySet entitySet)
 {
     this.DataType = returnType;
     this.EntitySet = entitySet;
 }
コード例 #28
0
        /// <summary>
        /// Determines whether an entity set is expected to be returned from a function call
        /// </summary>
        /// <param name="function">the function being called</param>
        /// <param name="entitySet">the expected entity set, if appropriate</param>
        /// <returns>whether or not an entity set is expected</returns>
        public static bool TryGetExpectedServiceOperationEntitySet(this Function function, out EntitySet entitySet)
        {
            ExceptionUtilities.CheckArgumentNotNull(function, "function");

            var bodyAnnotation = function.Annotations.OfType<FunctionBodyAnnotation>().SingleOrDefault();
            if (bodyAnnotation != default(FunctionBodyAnnotation))
            {
                var entityBodyType = bodyAnnotation.FunctionBody.ExpressionType as QueryEntityType;
                if (entityBodyType == null)
                {
                    var collectionBodyType = bodyAnnotation.FunctionBody.ExpressionType as QueryCollectionType;
                    if (collectionBodyType != null)
                    {
                        entityBodyType = collectionBodyType.ElementType as QueryEntityType;
                    }
                }

                if (entityBodyType != null)
                {
                    entitySet = entityBodyType.EntitySet;
                    return true;
                }
            }

            entitySet = null;
            return false;
        }
コード例 #29
0
 /// <summary>
 /// Removes an <see cref="EntitySet"/> from <see cref="EntitySets" /> collection.
 /// </summary>
 /// <param name="entitySet">Entity set to remove.</param>
 public void Remove(EntitySet entitySet)
 {
     ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");
     ExceptionUtilities.Assert(entitySet.Container == this, "Entity set was not added to this container");
     ExceptionUtilities.Assert(this.entitySetsList.Remove(entitySet), "Entity set was not added to this model");
     entitySet.Container = null;
 }
コード例 #30
0
 /// <summary>
 /// Generates the conventional edit link for the given entity: http://serviceRoot/SetName(keyValues)
 /// </summary>
 /// <param name="entitySet">The entity set of the entity</param>
 /// <param name="entityType">The type of the entity</param>
 /// <param name="keyValues">They values of the entity's key</param>
 /// <returns>The convention-based edit link</returns>
 public string GenerateEntityId(EntitySet entitySet, EntityType entityType, IEnumerable<NamedValue> keyValues)
 {
     // null checks performed by this helper
     var uri = this.GenerateEntityIdUri(entitySet, entityType, keyValues);
     return this.UriToStringConverter.ConvertToString(uri);
 }