本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
}