当前位置: 首页>>代码示例>>C#>>正文


C# IEdmEntitySet.EntityType方法代码示例

本文整理汇总了C#中IEdmEntitySet.EntityType方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmEntitySet.EntityType方法的具体用法?C# IEdmEntitySet.EntityType怎么用?C# IEdmEntitySet.EntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmEntitySet的用法示例。


在下文中一共展示了IEdmEntitySet.EntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ODataDeltaFeedSerializerTests

        public ODataDeltaFeedSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _path = new ODataPath(new EntitySetPathSegment(_customerSet));
            _customers = new[] {
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 10,
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 42,
                }
            };

            _deltaFeedCustomers = new EdmChangedObjectCollection(_customerSet.EntityType());
            EdmDeltaEntityObject newCustomer = new EdmDeltaEntityObject(_customerSet.EntityType());
            newCustomer.TrySetPropertyValue("ID", 10);
            newCustomer.TrySetPropertyValue("FirstName", "Foo");
            _deltaFeedCustomers.Add(newCustomer);

             _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();

            _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path };
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:31,代码来源:ODataDeltaFeedSerializerTests.cs

示例2: ParameterAliasNodeTranslatorTest

        public ParameterAliasNodeTranslatorTest()
        {
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<ParameterAliasCustomer>("Customers");
            builder.EntitySet<ParameterAliasOrder>("Orders");

            builder.EntityType<ParameterAliasCustomer>().Function("CollectionFunctionCall")
                .ReturnsCollection<int>().Parameter<int>("p1");

            builder.EntityType<ParameterAliasCustomer>().Function("EntityCollectionFunctionCall")
                .ReturnsCollectionFromEntitySet<ParameterAliasCustomer>("Customers").Parameter<int>("p1");

            builder.EntityType<ParameterAliasCustomer>().Function("SingleEntityFunctionCall")
                .Returns<ParameterAliasCustomer>().Parameter<int>("p1");

            builder.EntityType<ParameterAliasCustomer>().Function("SingleEntityFunctionCallWithoutParameters")
                .Returns<ParameterAliasCustomer>();

            builder.EntityType<ParameterAliasCustomer>().Function("SingleValueFunctionCall")
                .Returns<int>().Parameter<int>("p1");

            _model = builder.GetEdmModel();
            _customersEntitySet = _model.FindDeclaredEntitySet("Customers");
            _customerEntityType = _customersEntitySet.EntityType();
            _parameterAliasMappedNode = new ConstantNode(123);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:26,代码来源:ParameterAliasNodeTranslatorTest.cs

示例3: ConvertToODataEntry

        /// <summary>
        /// Converts an item from the data store into an ODataEntry.
        /// </summary>
        /// <param name="element">The item to convert.</param>
        /// <param name="entitySet">The entity set that the item belongs to.</param>
        /// <param name="targetVersion">The OData version this segment is targeting.</param>
        /// <returns>The converted ODataEntry.</returns>
        public static ODataEntry ConvertToODataEntry(object element, IEdmEntitySet entitySet, ODataVersion targetVersion)
        {
            IEdmEntityType entityType = entitySet.EntityType();

            Uri entryUri = BuildEntryUri(element, entitySet, targetVersion);

            var entry = new ODataEntry
            {
                // writes out the edit link including the service base uri  , e.g.: http://<serviceBase>/Customers('ALFKI')
                EditLink = entryUri,

                // writes out the self link including the service base uri  , e.g.: http://<serviceBase>/Customers('ALFKI')
                ReadLink = entryUri,

                // we use the EditLink as the Id for this entity to maintain convention,
                Id = entryUri,

                // writes out the <category term='Customer'/> element 
                TypeName = element.GetType().Namespace + "." + entityType.Name,

                Properties = entityType.StructuralProperties().Select(p => ConvertToODataProperty(element, p.Name)),
            };

            return entry;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:32,代码来源:ODataObjectModelConverter.cs

示例4: WriteEntry

        /// <summary>
        /// Writes an OData entry.
        /// </summary>
        /// <param name="writer">The ODataWriter that will write the entry.</param>
        /// <param name="element">The item from the data store to write.</param>
        /// <param name="entitySet">The entity set in the model that the entry belongs to.</param>
        /// <param name="model">The data store model.</param>
        /// <param name="targetVersion">The OData version this segment is targeting.</param>
        /// <param name="expandedNavigationProperties">A list of navigation property names to expand.</param>
        public static void WriteEntry(ODataWriter writer, object element, IEdmEntitySet entitySet, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties) 
        {
            var entry = ODataObjectModelConverter.ConvertToODataEntry(element, entitySet, targetVersion);

            writer.WriteStart(entry);

            // Here, we write out the links for the navigation properties off of the entity type
            WriteNavigationLinks(writer, element, entry.ReadLink, entitySet.EntityType(), model, targetVersion, expandedNavigationProperties);

            writer.WriteEnd();
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:20,代码来源:ResponseWriter.cs

示例5: ODataEntityTypeSerializerTests

        public ODataEntityTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();

            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Customer"), new ClrTypeAnnotation(typeof(Customer)));
            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Order"), new ClrTypeAnnotation(typeof(Order)));

            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            _serializerProvider = new DefaultODataSerializerProvider();
            _customerType = _model.GetEdmTypeReference(typeof(Customer)).AsEntity();
            _serializer = new ODataEntityTypeSerializer(_serializerProvider);
            _path = new ODataPath(new EntitySetPathSegment(_customerSet));
            _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path };
            _entityInstanceContext = new EntityInstanceContext(_writeContext, _customerSet.EntityType().AsReference(), _customer);
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:22,代码来源:ODataEntityTypeSerializerTests.cs

示例6: ODataFeedSerializerTests

        public ODataFeedSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _model.SetAnnotationValue(_customerSet.EntityType(), new ClrTypeAnnotation(typeof(Customer)));
            _customers = new[] {
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 10,
                },
                new Customer()
                {
                    FirstName = "Foo",
                    LastName = "Bar",
                    ID = 42,
                }
            };

            _customersType = _model.GetEdmTypeReference(typeof(Customer[])).AsCollection();

            _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model };
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFeedSerializerTests.cs

示例7: ProcessPostBody

        private object ProcessPostBody(IncomingRequestMessage message, IEdmEntitySet entitySet)
        {
            object lastNewInstance = null;

            using (var messageReader = new ODataMessageReader(message, this.GetDefaultReaderSettings(), this.Model))
            {
                var odataItemStack = new Stack<ODataItem>();
                var entryReader = messageReader.CreateODataEntryReader(entitySet.EntityType());
                IEdmEntitySet currentTargetEntitySet = entitySet;

                while (entryReader.Read())
                {
                    switch (entryReader.State)
                    {
                        case ODataReaderState.EntryStart:
                            entryReader.Item.SetAnnotation(new TargetEntitySetAnnotation { TargetEntitySet = currentTargetEntitySet });
                            odataItemStack.Push(entryReader.Item);
                            break;

                        case ODataReaderState.EntryEnd:
                            {
                                var entry = (ODataEntry)entryReader.Item;

                                var targetEntitySet = entry.GetAnnotation<TargetEntitySetAnnotation>().TargetEntitySet;
                                object newInstance = this.DataContext.CreateNewItem(targetEntitySet);

                                foreach (var property in entry.Properties)
                                {
                                    DataContext.UpdatePropertyValue(newInstance, property.Name, property.Value);
                                }

                                var boundNavPropAnnotation = odataItemStack.Pop().GetAnnotation<BoundNavigationPropertyAnnotation>();
                                if (boundNavPropAnnotation != null)
                                {
                                    foreach (var boundProperty in boundNavPropAnnotation.BoundProperties)
                                    {
                                        bool isCollection = boundProperty.Item1.IsCollection == true;
                                        object propertyValue = isCollection ? boundProperty.Item2 : ((IEnumerable<object>)boundProperty.Item2).Single();
                                        DataContext.UpdatePropertyValue(newInstance, boundProperty.Item1.Name, propertyValue);
                                    }
                                }

                                var parentItem = odataItemStack.Count > 0 ? odataItemStack.Peek() : null;
                                if (parentItem != null)
                                {
                                    // This new entry belongs to a navigation property and/or feed -
                                    // propagate it up the tree for further processing.
                                    AddChildInstanceAnnotation(parentItem, newInstance);
                                }

                                this.DataContext.AddItem(targetEntitySet, newInstance);
                                lastNewInstance = newInstance;
                            }

                            break;

                        case ODataReaderState.FeedStart:
                            odataItemStack.Push(entryReader.Item);
                            break;

                        case ODataReaderState.FeedEnd:
                            {
                                var childAnnotation = odataItemStack.Pop().GetAnnotation<ChildInstanceAnnotation>();

                                var parentNavLink = odataItemStack.Count > 0 ? odataItemStack.Peek() as ODataNavigationLink : null;
                                if (parentNavLink != null)
                                {
                                    // This feed belongs to a navigation property -
                                    // propagate it up the tree for further processing.
                                    AddChildInstanceAnnotation(parentNavLink, childAnnotation.ChildInstances ?? new object[0]);
                                }
                            }

                            break;

                        case ODataReaderState.NavigationLinkStart:
                            {
                                odataItemStack.Push(entryReader.Item);
                                var navigationLink = (ODataNavigationLink)entryReader.Item;
                                var navigationProperty = (IEdmNavigationProperty)currentTargetEntitySet.EntityType().FindProperty(navigationLink.Name);

                                // Current model implementation doesn't expose associations otherwise this would be much cleaner.
                                currentTargetEntitySet = this.Model.EntityContainer.EntitySets().Single(s => s.EntityType() == navigationProperty.Type.Definition);
                            }

                            break;

                        case ODataReaderState.NavigationLinkEnd:
                            {
                                var navigationLink = (ODataNavigationLink)entryReader.Item;
                                var childAnnotation = odataItemStack.Pop().GetAnnotation<ChildInstanceAnnotation>();
                                if (childAnnotation != null)
                                {
                                    // Propagate the bound entries to the parent entry.
                                    AddBoundNavigationPropertyAnnotation(odataItemStack.Peek(), navigationLink, childAnnotation.ChildInstances);
                                }
                            }

                            break;
                    }
//.........这里部分代码省略.........
开发者ID:AlineGuan,项目名称:odata.net,代码行数:101,代码来源:CreateHandler.cs

示例8: ProcessPutBody

        private object ProcessPutBody(IncomingRequestMessage message, IEdmEntitySet entitySet, IDictionary<string, object> entityKeys) 
        {
            using (var messageReader = new ODataMessageReader(message, this.GetDefaultReaderSettings(), this.Model))
            {
                var entryReader = messageReader.CreateODataEntryReader(entitySet.EntityType());

                while (entryReader.Read())
                {
                    switch(entryReader.State)
                    {
                        case ODataReaderState.EntryEnd:
                            var entry = (ODataEntry)entryReader.Item;
                            foreach (var property in entry.Properties)
                            {
                                this.DataContext.UpdateItem(entitySet, entityKeys, property.Name, property.Value);
                            }

                            break;
                    }
                }
            }

            return this.DataContext.GetItem(entitySet, entityKeys);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:24,代码来源:UpdateHandler.cs

示例9: WriteProperty

            private void WriteProperty(OdcmClass odcmClass, IEdmEntitySet entitySet)
            {
                var odcmProperty = new OdcmProperty(entitySet.Name)
                {
                    Class = odcmClass,
                    Type = ResolveType(entitySet.EntityType().Name, entitySet.EntityType().Namespace),
                    IsCollection = true,
                    IsLink = true
                };

                AddVocabularyAnnotations(odcmProperty, entitySet);

                odcmClass.Properties.Add(odcmProperty);
            }
开发者ID:peternied,项目名称:Vipr,代码行数:14,代码来源:OdcmReader.cs

示例10: GetPathForEntity

        static string GetPathForEntity(IEdmEntitySet entitySet)
        {
            string singleEntityPath = "/" + entitySet.Name + "(";
            foreach (var key in entitySet.EntityType().Key())
            {
                if (key.Type.Definition.TypeKind == EdmTypeKind.Primitive &&
                    (key.Type.Definition as IEdmPrimitiveType).PrimitiveKind == EdmPrimitiveTypeKind.String)
                {
                    singleEntityPath += "'{" + key.Name + "}', ";
                }
                else
                {
                    singleEntityPath += "{" + key.Name + "}, ";
                }
            }
            singleEntityPath = singleEntityPath.Substring(0, singleEntityPath.Length - 2);
            singleEntityPath += ")";

            return singleEntityPath;
        }
开发者ID:TomDu,项目名称:lab,代码行数:20,代码来源:Program.cs

示例11: CreateSwaggerPathForOperationOfEntity

        static JObject CreateSwaggerPathForOperationOfEntity(IEdmOperation operation, IEdmEntitySet entitySet)
        {
            JArray swaggerParameters = new JArray();

            foreach (var key in entitySet.EntityType().Key())
            {
                string format;
                string type = GetPrimitiveTypeAndFormat(key.Type.Definition as IEdmPrimitiveType, out format);
                swaggerParameters.Parameter(key.Name, "path", "key: " + key.Name, type, format);
            }

            foreach (var parameter in operation.Parameters.Skip(1))
            {
                swaggerParameters.Parameter(parameter.Name, operation is IEdmFunction ? "path" : "body",
                    "parameter: " + parameter.Name, parameter.Type.Definition);
            }

            JObject swaggerResponses = new JObject();
            if (operation.ReturnType == null)
            {
                swaggerResponses.Response("204", "Empty response");
            }
            else
            {
                swaggerResponses.Response("200", "Response from " + operation.Name,
                    operation.ReturnType.Definition);
            }

            JObject swaggerOperation = new JObject()
                .Summary("Call operation  " + operation.Name)
                .Description("Call operation  " + operation.Name)
                .Tags(entitySet.Name, operation is IEdmFunction ? "Function" : "Action");

            if (swaggerParameters.Count > 0)
            {
                swaggerOperation.Parameters(swaggerParameters);
            }
            swaggerOperation.Responses(swaggerResponses.DefaultErrorResponse());
            return new JObject()
                {
                    {operation is IEdmFunction ? "get" : "post", swaggerOperation}
                };
        }
开发者ID:TomDu,项目名称:lab,代码行数:43,代码来源:Program.cs

示例12: BuildEntryUri

 /// <summary>
 /// Generates the URI used to reference an entry in the data store.
 /// </summary>
 /// <param name="entry">The entry instance to build the URI for.</param>
 /// <param name="entitySet">The entity set that the entry belongs to.</param>
 /// <param name="targetVersion">The OData version this segment is targeting.</param>
 /// <returns>The generated URI.</returns>
 public static Uri BuildEntryUri(object entry, IEdmEntitySet entitySet, ODataVersion targetVersion)
 {
     string keySegment = BuildKeyString(entry, entitySet.EntityType(), targetVersion);
     return new Uri(ServiceConstants.ServiceBaseUri, entitySet.Name + "(" + keySegment + ")");
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:12,代码来源:ODataObjectModelConverter.cs

示例13: CreateSwaggerPathForEntity

        static JObject CreateSwaggerPathForEntity(IEdmEntitySet entitySet)
        {
            var keyParameters = new JArray();
            foreach (var key in entitySet.EntityType().Key())
            {
                string format;
                string type = GetPrimitiveTypeAndFormat(key.Type.Definition as IEdmPrimitiveType, out format);
                keyParameters.Parameter(key.Name, "path", "key: " + key.Name, type, format);
            }

            return new JObject()
            {
                {
                    "get", new JObject()
                        .Summary("Get entity from " + entitySet.Name + " by key.")
                        .Description("Returns the entity with the key from " + entitySet.Name)
                        .Tags(entitySet.Name)
                        .Parameters((keyParameters.DeepClone() as JArray)
                            .Parameter("$select", "query", "description", "string")
                        )
                        .Responses(new JObject()
                            .Response("200", "EntitySet " + entitySet.Name, entitySet.EntityType())
                            .DefaultErrorResponse()
                        )
                },
                {
                    "patch", new JObject()
                        .Summary("Update entity in EntitySet " + entitySet.Name)
                        .Description("Update entity in EntitySet " + entitySet.Name)
                        .Tags(entitySet.Name)
                        .Parameters((keyParameters.DeepClone() as JArray)
                            .Parameter(entitySet.EntityType().Name, "body", "The entity to patch",
                                entitySet.EntityType())
                        )
                        .Responses(new JObject()
                            .Response("204", "Empty response")
                            .DefaultErrorResponse()
                        )
                },
                {
                    "delete", new JObject()
                        .Summary("Delete entity in EntitySet " + entitySet.Name)
                        .Description("Delete entity in EntitySet " + entitySet.Name)
                        .Tags(entitySet.Name)
                        .Parameters((keyParameters.DeepClone() as JArray)
                            .Parameter("If-Match", "header", "If-Match header", "string")
                        )
                        .Responses(new JObject()
                            .Response("204", "Empty response")
                            .DefaultErrorResponse()
                        )
                }
            };
        }
开发者ID:TomDu,项目名称:lab,代码行数:54,代码来源:Program.cs

示例14: AddReferenceProperty

        /// <summary>Helper method to add a reference property.</summary>
        /// <param name="entityType">The entity type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="targetEntitySet">The entity set the resource reference property points to.</param>
        /// <param name="targetEntityType">The entity type the entity set reference property points to.</param>
        /// <param name="resourceSetReference">true if the property should be a entity set reference, false if it should be an entity reference.</param>
        private IEdmNavigationProperty AddReferenceProperty(IEdmEntityType entityType, string name, IEdmEntitySet targetEntitySet, IEdmEntityType targetEntityType, bool resourceSetReference, bool containsTarget)
        {
            targetEntityType = targetEntityType ?? targetEntitySet.EntityType();

            IEdmTypeReference navPropertyTypeReference = resourceSetReference
                ? new EdmCollectionType(targetEntityType.ToTypeReference(true)).ToTypeReference(true)
                : targetEntityType.ToTypeReference(true);

            IEdmNavigationProperty navigationProperty = AddNavigationProperty(
                entityType,
                name,
                EdmOnDeleteAction.None,
                navPropertyTypeReference,
                containsTarget);

            return navigationProperty;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:23,代码来源:ConstructableMetadata.cs

示例15: ConvertToTaupoEntitySet

        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;
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:8,代码来源:EdmToTaupoModelConverter.cs


注:本文中的IEdmEntitySet.EntityType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。