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


C# DataServiceContext.GetType方法代码示例

本文整理汇总了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;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:29,代码来源:DataServiceState.cs

示例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);
                }
            }
        }
开发者ID:davidebbo-test,项目名称:DynamicDataWCFDataService,代码行数:41,代码来源:DataServiceLinqDataSource.cs


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