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


C# ObjectContext.GetType方法代码示例

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


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

示例1: CreateModel

        /// <summary>
        /// Creates an <see cref="IEdmModel"/> based on a combination of the ObjectContext's properties and it's metadata workspace
        /// </summary>
        /// <param name="context">The object context instance</param>
        /// <returns>An <see cref="IEdmModel"/> based on a combination of the ObjectContext's properties and it's metadata workspace</returns>
        public static IEdmModel CreateModel(ObjectContext context)
        {
            Assembly objectLayerAssembly = context.GetType().Assembly;
            ConstructableMetadata metadata = new ConstructableMetadata(context.DefaultContainerName, ("DBNorthwindModel"));
            foreach (EntityType entityType in context.MetadataWorkspace.GetItems<EntityType>(DataSpace.CSpace))
            {
                Type clrType = objectLayerAssembly.GetType("Microsoft.Test.Taupo.OData.WCFService.Model." + entityType.Name, false, true);
                IEdmEntityType edmEntityType = metadata.AddEntityType(entityType.Name, clrType, null, false, "DBNorthwindModel");
                AddProperties(metadata, entityType.Properties, edmEntityType);
            }

            foreach (var entitySet in context.GetType().GetProperties().Where(property => property.PropertyType.GetInterface("IQueryable") != null))
            {
                Type entityType = entitySet.PropertyType.GetGenericArguments().First();
                IEdmEntityType edmEntityType = metadata.FindType("DBNorthwindModel." + entityType.Name) as IEdmEntityType;
                metadata.AddEntitySet(entitySet.Name, edmEntityType);
            }

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

示例2: EFDataModelProvider

        public EFDataModelProvider(object contextInstance, Func<object> contextFactory) {
            ContextFactory = contextFactory;
            RelationshipEndLookup = new Dictionary<long, EFColumnProvider>();
            TableEndLookup = new Dictionary<EntityType, EFTableProvider>();

            _context = (ObjectContext)contextInstance ?? (ObjectContext)CreateContext();
            ContextType = _context.GetType();

            // get a "container" (a scope at the instance level)
            EntityContainer container = _context.MetadataWorkspace.GetEntityContainer(_context.DefaultContainerName, DataSpace.CSpace);
            // load object space metadata
            _context.MetadataWorkspace.LoadFromAssembly(ContextType.Assembly);
            _objectSpaceItems = (ObjectItemCollection)_context.MetadataWorkspace.GetItemCollection(DataSpace.OSpace);

            var tables = new List<TableProvider>();

            // Create a dictionary from entity type to entity set. The entity type should be at the root of any inheritance chain.
            IDictionary<EntityType, EntitySet> entitySetLookup = container.BaseEntitySets.OfType<EntitySet>().ToDictionary(e => e.ElementType);

            // Create a lookup from parent entity to entity
            ILookup<EntityType, EntityType> derivedTypesLookup = _context.MetadataWorkspace.GetItems<EntityType>(DataSpace.CSpace).ToLookup(e => (EntityType)e.BaseType);

            // Keeps track of the current entity set being processed
            EntitySet currentEntitySet = null;

            // Do a DFS to get the inheritance hierarchy in order
            // i.e. Consider the hierarchy
            // null -> Person
            // Person -> Employee, Contact
            // Employee -> SalesPerson, Programmer
            // We'll walk the children in a depth first order -> Person, Employee, SalesPerson, Programmer, Contact.
            var objectStack = new Stack<EntityType>();
            // Start will null (the root of the hierarchy)
            objectStack.Push(null);
            while (objectStack.Any()) {
                EntityType entityType = objectStack.Pop();
                if (entityType != null) {
                    // Update the entity set when we are at another root type (a type without a base type).
                    if (entityType.BaseType == null) {
                        currentEntitySet = entitySetLookup[entityType];
                    }

                    var table = CreateTableProvider(currentEntitySet, entityType);
                    tables.Add(table);
                }

                foreach (EntityType derivedEntityType in derivedTypesLookup[entityType]) {
                    // Push the derived entity types on the stack
                    objectStack.Push(derivedEntityType);
                }
            }

            _tables = tables.AsReadOnly();
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:54,代码来源:EFDataModelProvider.cs

示例3: CreateEntityObject

 private EntityObject CreateEntityObject(ObjectContext context, string entitySetName)
 {
     MetadataProvider metadataProvider = new MetadataProvider(context.MetadataWorkspace);
     Type sysTableType = context.GetType().Assembly.GetTypes().Where(c => c.Name == metadataProvider.GetEntitySetType(context.DefaultContainerName, entitySetName).Name).ElementAt(0);
     EntityObject entityObject = (EntityObject)sysTableType.GetConstructors()[0].Invoke(null);
     return entityObject;
 }
开发者ID:san90279,项目名称:UK_OAS,代码行数:7,代码来源:EFAutoNumber.cs

示例4: CreateObject

 /// <summary>
 /// Create a new instance of the given clrtype using ObjectContext.CreateObject method
 /// </summary>
 /// <param name="context">current object context instance.</param>
 /// <param name="clrType">clrType whose instance needs to be created.</param>
 /// <returns>the instance returned by ObjectContext.</returns>
 private static object CreateObject(ObjectContext context, Type clrType)
 {
     // this.ObjectContext.CreateObject<T>()
     MethodInfo createObjectMethod = context.GetType().GetMethod("CreateObject", BindingFlags.Public | BindingFlags.Instance);
     return createObjectMethod.MakeGenericMethod(clrType).Invoke(context, null);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:12,代码来源:ObjectContextServiceProvider.cs

示例5: FindContainerProperty

 protected PropertyInfo FindContainerProperty(ObjectContext context, string containerName)
 {
     return context.GetType().GetProperties().Where(propi => propi.Name == containerName).First();
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:4,代码来源:EdmWorkspace.cs


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