本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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);
}
示例5: FindContainerProperty
protected PropertyInfo FindContainerProperty(ObjectContext context, string containerName)
{
return context.GetType().GetProperties().Where(propi => propi.Name == containerName).First();
}