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; }
/// <summary> /// Gets list of values /// </summary> /// <param name="context">ITypeDescriptorContext</param> /// <returns>List of values</returns> public override List<string> GetListOfValues(System.ComponentModel.ITypeDescriptorContext context) { if (context.Instance != null && context.PropertyDescriptor != null) { var edmItemAttribute = context.PropertyDescriptor.Attributes[typeof(EdmItemAttribute)]; if (edmItemAttribute == null) { throw new ObjectNotFoundException(string.Format("EdmItemAttribute not found on property:{0}.", context.PropertyDescriptor.Name)); } if (edmItemAttribute.Equals(EdmItemAttribute.EdmMetadataAttribute)) { return MetadataProvider.GetMetadataFiles(DTE.CurrentDirectory); } else { var command = GetRelatedCommand(context.Instance); var provider = new MetadataProvider(DTE.CurrentDirectory, command.MetadataFile); if (edmItemAttribute.Equals(EdmItemAttribute.EdmEntitySetAttribute)) { return provider.GetEntitySetNames(command.ContextName); } var entitySetName = context.PropertyDescriptor.Attributes[typeof(TargetEntitySetItemAttribute)] == null ? command.EntitySetName : GetRelatedEntitySet(context.Instance).TargetEntitySet; var entityTypeName = provider.GetEntitySetType(command.ContextName, entitySetName); if (edmItemAttribute.Equals(EdmItemAttribute.EdmScalePropertyAttribute)) { return provider.GetPropertyNames(command.ContextName, entityTypeName); } else if (edmItemAttribute.Equals(EdmItemAttribute.EdmNavigationPropertyAttribute)) { return provider.GetNavgationPropertyNames(command.ContextName, entityTypeName); } else { throw new NotSupportedException(string.Format("EdmItemAttribute:{0} not supported.", edmItemAttribute.TypeId)); } } } return new List<string>(); }