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


C# EntityInstanceContext.GetPropertyValue方法代码示例

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


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

示例1: WriteExpandedNavigationProperty

        private void WriteExpandedNavigationProperty(
            KeyValuePair<IEdmNavigationProperty, SelectExpandClause> navigationPropertyToExpand,
            EntityInstanceContext entityInstanceContext,
            ODataWriter writer)
        {
            Contract.Assert(entityInstanceContext != null);
            Contract.Assert(writer != null);

            IEdmNavigationProperty navigationProperty = navigationPropertyToExpand.Key;
            SelectExpandClause selectExpandClause = navigationPropertyToExpand.Value;

            object propertyValue = entityInstanceContext.GetPropertyValue(navigationProperty.Name);

            if (propertyValue == null)
            {
                if (navigationProperty.Type.IsCollection())
                {
                    // A navigation property whose Type attribute specifies a collection, the collection always exists,
                    // it may just be empty.
                    // If a collection of entities can be related, it is represented as a JSON array. An empty
                    // collection of entities (one that contains no entities) is represented as an empty JSON array.
                    writer.WriteStart(new ODataFeed());
                }
                else
                {
                    // If at most one entity can be related, the value is null if no entity is currently related.
                    writer.WriteStart(entry: null);
                }

                writer.WriteEnd();
            }
            else
            {
                // create the serializer context for the expanded item.
                ODataSerializerContext nestedWriteContext = new ODataSerializerContext(entityInstanceContext, selectExpandClause, navigationProperty);

                // write object.
                ODataEdmTypeSerializer serializer = SerializerProvider.GetEdmTypeSerializer(navigationProperty.Type);
                if (serializer == null)
                {
                    throw new SerializationException(
                        Error.Format(SRResources.TypeCannotBeSerialized, navigationProperty.Type.ToTraceString(), typeof(ODataMediaTypeFormatter).Name));
                }

                serializer.WriteObjectInline(propertyValue, navigationProperty.Type, writer, nestedWriteContext);
            }
        }
开发者ID:BarclayII,项目名称:WebApi,代码行数:47,代码来源:ODataEntityTypeSerializer.cs

示例2: CreateStructuralProperty

        /// <summary>
        /// Creates the <see cref="ODataProperty"/> to be written for the given entity and the structural property.
        /// </summary>
        /// <param name="structuralProperty">The EDM structural property being written.</param>
        /// <param name="entityInstanceContext">The context for the entity instance being written.</param>
        /// <returns>The <see cref="ODataProperty"/> to write.</returns>
        public virtual ODataProperty CreateStructuralProperty(IEdmStructuralProperty structuralProperty, EntityInstanceContext entityInstanceContext)
        {
            if (structuralProperty == null)
            {
                throw Error.ArgumentNull("structuralProperty");
            }
            if (entityInstanceContext == null)
            {
                throw Error.ArgumentNull("entityInstanceContext");
            }

            ODataSerializerContext writeContext = entityInstanceContext.SerializerContext;

            ODataEdmTypeSerializer serializer = SerializerProvider.GetEdmTypeSerializer(structuralProperty.Type);
            if (serializer == null)
            {
                throw new SerializationException(
                    Error.Format(SRResources.TypeCannotBeSerialized, structuralProperty.Type.FullName(), typeof(ODataMediaTypeFormatter).Name));
            }

            object propertyValue = entityInstanceContext.GetPropertyValue(structuralProperty.Name);

            IEdmTypeReference propertyType = structuralProperty.Type;
            if (propertyValue != null)
            {
                IEdmTypeReference actualType = writeContext.GetEdmType(propertyValue, propertyValue.GetType());
                if (propertyType != null && propertyType != actualType)
                {
                    propertyType = actualType;
                }
            }

            return serializer.CreateProperty(propertyValue, propertyType, structuralProperty.Name, writeContext);
        }
开发者ID:BarclayII,项目名称:WebApi,代码行数:40,代码来源:ODataEntityTypeSerializer.cs

示例3: CreateETag

        /// <summary>
        /// Creates the ETag for the given entity.
        /// </summary>
        /// <param name="entityInstanceContext">The context for the entity instance being written.</param>
        /// <returns>The created ETag.</returns>
        public virtual string CreateETag(EntityInstanceContext entityInstanceContext)
        {
            if (entityInstanceContext.Request != null)
            {
                HttpConfiguration configuration = entityInstanceContext.Request.GetConfiguration();
                if (configuration == null)
                {
                    throw Error.InvalidOperation(SRResources.RequestMustContainConfiguration);
                }

                IEnumerable<IEdmStructuralProperty> concurrencyProperties =
                    entityInstanceContext.EntityType.GetConcurrencyProperties().OrderBy(c => c.Name);

                IDictionary<string, object> properties = new Dictionary<string, object>();
                foreach (IEdmStructuralProperty etagProperty in concurrencyProperties)
                {
                    properties.Add(etagProperty.Name, entityInstanceContext.GetPropertyValue(etagProperty.Name));
                }
                EntityTagHeaderValue etagHeaderValue = configuration.GetETagHandler().CreateETag(properties);
                if (etagHeaderValue != null)
                {
                    return etagHeaderValue.ToString();
                }
            }

            return null;
        }
开发者ID:BarclayII,项目名称:WebApi,代码行数:32,代码来源:ODataEntityTypeSerializer.cs

示例4: WriteExpandedNavigationProperty

        private void WriteExpandedNavigationProperty(
            KeyValuePair<IEdmNavigationProperty, SelectExpandClause> navigationPropertyToExpand,
            EntityInstanceContext entityInstanceContext,
            ODataWriter writer)
        {
            Contract.Assert(entityInstanceContext != null);
            Contract.Assert(writer != null);

            ODataSerializerContext writeContext = entityInstanceContext.SerializerContext;

            IEdmNavigationProperty navigationProperty = navigationPropertyToExpand.Key;
            SelectExpandClause selectExpandClause = navigationPropertyToExpand.Value;

            object propertyValue = entityInstanceContext.GetPropertyValue(navigationProperty.Name);
            if (propertyValue != null)
            {
                // backup current context.
                SelectExpandClause currentSelectExpandClause = writeContext.SelectExpandClause;
                IEdmEntitySet currentEntitySet = writeContext.EntitySet;

                // update the context with child context.
                writeContext.SelectExpandClause = selectExpandClause;
                writeContext.EntitySet = currentEntitySet.FindNavigationTarget(navigationProperty);

                // write object.
                Type propertyType = propertyValue.GetType();
                ODataEdmTypeSerializer serializer = SerializerProvider.GetEdmTypeSerializer(writeContext.Model, propertyValue);
                if (serializer == null)
                {
                    throw new SerializationException(
                        Error.Format(SRResources.TypeCannotBeSerialized, propertyType.FullName, typeof(ODataMediaTypeFormatter).Name));
                }

                serializer.WriteObjectInline(propertyValue, writer, writeContext);

                // revert back context.
                writeContext.SelectExpandClause = currentSelectExpandClause;
                writeContext.EntitySet = currentEntitySet;
            }
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:40,代码来源:ODataEntityTypeSerializer.cs

示例5: WriteExpandedNavigationProperty

        private void WriteExpandedNavigationProperty(
            KeyValuePair<IEdmNavigationProperty, SelectExpandClause> navigationPropertyToExpand,
            EntityInstanceContext entityInstanceContext,
            ODataWriter writer)
        {
            Contract.Assert(entityInstanceContext != null);
            Contract.Assert(writer != null);

            IEdmNavigationProperty navigationProperty = navigationPropertyToExpand.Key;
            SelectExpandClause selectExpandClause = navigationPropertyToExpand.Value;

            object propertyValue = entityInstanceContext.GetPropertyValue(navigationProperty.Name);
            if (propertyValue != null)
            {
                // create the serializer context for the expanded item.
                ODataSerializerContext nestedWriteContext = new ODataSerializerContext(entityInstanceContext, selectExpandClause, navigationProperty);

                // write object.
                ODataEdmTypeSerializer serializer = SerializerProvider.GetEdmTypeSerializer(navigationProperty.Type);
                if (serializer == null)
                {
                    throw new SerializationException(
                        Error.Format(SRResources.TypeCannotBeSerialized, navigationProperty.Type.ToTraceString(), typeof(ODataMediaTypeFormatter).Name));
                }

                serializer.WriteObjectInline(propertyValue, navigationProperty.Type, writer, nestedWriteContext);
            }
        }
开发者ID:modulexcite,项目名称:aspnetwebstack-1,代码行数:28,代码来源:ODataEntityTypeSerializer.cs

示例6: CreateETagAsync

		/// <summary>
		/// Creates the ETag for the given entity.
		/// </summary>
		/// <param name="entityInstanceContext">The context for the entity instance being written.</param>
		/// <returns>The created ETag.</returns>
		public virtual Task<string> CreateETagAsync(EntityInstanceContext entityInstanceContext)
		{
			if (entityInstanceContext.Request != null)
			{
				IEnumerable<IEdmStructuralProperty> concurrencyProperties =
					entityInstanceContext.EntityType.GetConcurrencyProperties().OrderBy(c => c.Name);

				IDictionary<string, object> properties = new Dictionary<string, object>();
				foreach (IEdmStructuralProperty etagProperty in concurrencyProperties)
				{
					properties.Add(etagProperty.Name, entityInstanceContext.GetPropertyValue(etagProperty.Name));
				}
				EntityTagHeaderValue etagHeaderValue = entityInstanceContext.Request.ETagHandler().CreateETag(properties);
				if (etagHeaderValue != null)
				{
					return Task.FromResult(etagHeaderValue.ToString());
				}
			}

			return Task.FromResult((string)null);
		}
开发者ID:joshcomley,项目名称:WebApi,代码行数:26,代码来源:ODataEntityTypeSerializer.cs

示例7: WriteExpandedNavigationProperty

        private void WriteExpandedNavigationProperty(
            KeyValuePair<IEdmNavigationProperty, SelectExpandClause> navigationPropertyToExpand,
            EntityInstanceContext entityInstanceContext,
            ODataWriter writer)
        {
            Contract.Assert(entityInstanceContext != null);
            Contract.Assert(writer != null);

            ODataSerializerContext writeContext = entityInstanceContext.SerializerContext;

            IEdmNavigationProperty navigationProperty = navigationPropertyToExpand.Key;
            SelectExpandClause selectExpandClause = navigationPropertyToExpand.Value;

            object propertyValue = entityInstanceContext.GetPropertyValue(navigationProperty.Name);
            if (propertyValue != null)
            {
                // create the serializer context for the expanded item.
                ODataSerializerContext nestedWriteContext = new ODataSerializerContext(writeContext);
                nestedWriteContext.SelectExpandClause = selectExpandClause;
                nestedWriteContext.EntitySet = writeContext.EntitySet.FindNavigationTarget(navigationProperty);
                nestedWriteContext.IsNested = true;

                // write object.
                Type propertyType = propertyValue.GetType();
                ODataEdmTypeSerializer serializer = SerializerProvider.GetEdmTypeSerializer(writeContext.Model, propertyValue);
                if (serializer == null)
                {
                    throw new SerializationException(
                        Error.Format(SRResources.TypeCannotBeSerialized, propertyType.FullName, typeof(ODataMediaTypeFormatter).Name));
                }
                serializer.WriteObjectInline(propertyValue, writer, nestedWriteContext);
            }
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:33,代码来源:ODataEntityTypeSerializer.cs


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