本文整理汇总了C#中DataServiceContext.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.GetType方法的具体用法?C# DataServiceContext.GetType怎么用?C# DataServiceContext.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataServiceContext
的用法示例。
在下文中一共展示了DataServiceContext.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
static public DataServiceState Save(DataServiceContext context, Dictionary<string,object> collections)
{
List<Type> knownTypes = GetKnownTypes(context);
Dictionary<EntityDescriptor, Guid> entityDescriptorToId;
ContextState contextState = context.SaveState(out entityDescriptorToId);
string contextAsString = SerializeContextToString(contextState, knownTypes);
var collectionsState = new Dictionary<string, CollectionState>();
if (collections != null)
{
foreach (KeyValuePair<string, object> kvp in collections)
{
IDataServiceCollection collection = (IDataServiceCollection) kvp.Value;
CollectionState collectionState = collection.SaveState(context, entityDescriptorToId);
collectionsState.Add(kvp.Key, collectionState);
}
}
DataServiceState state = new DataServiceState()
{
CollectionsState = collectionsState,
ContextAsString = contextAsString,
ContextTypeName = context.GetType().AssemblyQualifiedName,
KnownTypeNames = knownTypes.Select(t => t.AssemblyQualifiedName).ToList()
};
return state;
}
示例2: ProcessForeignKeys
private void ProcessForeignKeys(DataServiceContext dataServiceContext, object dataObject, IDictionary values)
{
foreach (string key in values.Keys) {
// Check if it looks like a FK, e.g. Category.CategoryID
string[] parts = key.Split('.');
if (parts.Length != 2)
continue;
// Get the name of the entity ref property, e.g. Category
string entityRefPropertyName = parts[0];
// Get the PropertyInfo for the entity ref property
PropertyInfo propInfo = dataObject.GetType().GetProperty(entityRefPropertyName);
object entityRefObject = null;
if (values[key] != null) {
// Create an 'empty' related entity, e.g a Category
entityRefObject = Activator.CreateInstance(propInfo.PropertyType);
// Set the PK in the related entity, e.g. set the CategoryID in the Category
PropertyInfo subPropInfo = propInfo.PropertyType.GetProperty(parts[1]);
subPropInfo.SetValue(
entityRefObject,
Convert.ChangeType(values[key], subPropInfo.PropertyType),
null);
}
// Find the entity set property for the association table e.g. Categories
PropertyInfo entitySetProp = DataServiceUtilities.FindEntitySetProperty(
dataServiceContext.GetType(), propInfo.PropertyType);
// Attach the related entity and set it as the link on the main entity
if (entitySetProp != null) {
if (entityRefObject != null) {
dataServiceContext.AttachTo(entitySetProp.Name, entityRefObject);
}
dataServiceContext.SetLink(dataObject, entityRefPropertyName, entityRefObject);
}
}
}