Ejemplo n.º 1
0
        protected EntityDataSourceColumn(string displayName, EntityDataSourceColumn controllingColumn)
        {
            EntityDataSourceUtil.CheckArgumentNull(displayName, "displayName");

            this.DisplayName       = displayName;
            this.ControllingColumn = controllingColumn;
        }
Ejemplo n.º 2
0
        internal override string GetEntitySqlValue()
        {
            // it.NavigationPropertyName
            string result = EntityDataSourceUtil.EntitySqlElementAlias + "." + EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.navigationProperty.Name);

            return(result);
        }
Ejemplo n.º 3
0
        private static void AddReferenceKeyColumns(List <EntityDataSourceColumn> columns, MetadataWorkspace ocWorkspace, EntitySet entitySet, EntityType entityType, Dictionary <EdmProperty, EntityDataSourcePropertyColumn> entityProperties)
        {
            foreach (AssociationSetEnd toEnd in GetReferenceEnds(entitySet, entityType, /*forKey*/ true))
            {
                ReferentialConstraint constraint;
                bool isContained = EntityDataSourceUtil.IsContained(toEnd, out constraint);

                // Create a group for the end columns
                EntityType toType    = EntityDataSourceUtil.GetEntityType(toEnd);
                Type       clrToType = EntityDataSourceUtil.GetClrType(ocWorkspace, toType);

                EntityDataSourceReferenceGroup group = EntityDataSourceReferenceGroup.Create(clrToType, toEnd);

                // Create a column for every key
                foreach (EdmProperty keyMember in GetEntityType(toEnd).KeyMembers)
                {
                    EntityDataSourceColumn controllingColumn = null;
                    if (isContained)
                    {
                        // if this key is 'contained' in the entity, make the referential constrained
                        // property the principal for the column
                        int ordinalInConstraint = constraint.FromProperties.IndexOf(keyMember);

                        // find corresponding member in the current (dependent) entity
                        EdmProperty correspondingProperty = constraint.ToProperties[ordinalInConstraint];

                        controllingColumn = entityProperties[correspondingProperty];
                    }
                    columns.Add(new EntityDataSourceReferenceKeyColumn(ocWorkspace, group, keyMember, controllingColumn));
                }
            }
        }
Ejemplo n.º 4
0
        private void SetEntityKeyProperties(
            List <KeyValuePair <EntityDataSourceReferenceKeyColumn, object> > referenceList, bool overwriteSameValue)
        {
            EntityDataSourceUtil.CheckArgumentNull(referenceList, "referenceList");

            var groups = referenceList.GroupBy(r => r.Key.Group);

            foreach (var group in groups)
            {
                Dictionary <string, object> partialKeys = new Dictionary <string, object>();

                foreach (KeyValuePair <EntityDataSourceReferenceKeyColumn, object> reference in group)
                {
                    // convert the value as needed
                    EntityDataSourceReferenceKeyColumn column = reference.Key;
                    object keyValue = reference.Value;

                    if (null == keyValue)
                    {
                        partialKeys = null;
                        break;
                    }

                    partialKeys.Add(column.KeyMember.Name, keyValue);
                }

                // we only set the entitykey for once, although there might be more than one
                // properties descriptor associated with the same entitykey
                group.Key.SetKeyValues(this, partialKeys);
            }
        }
Ejemplo n.º 5
0
        protected EntityDataSourceReferenceValueColumn(MetadataWorkspace ocWorkspace, NavigationProperty navigationProperty)
            : base(EntityDataSourceUtil.CheckArgumentNull(navigationProperty, "navigationProperty").Name)
        {
            EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace");

            this.navigationProperty = navigationProperty;
        }
        internal static EntityDataSourceReferenceGroup Create(Type entityType, AssociationSetEnd end)
        {
            EntityDataSourceUtil.CheckArgumentNull(entityType, "entityType");

            Type groupType = typeof(EntityDataSourceReferenceGroup <>).MakeGenericType(entityType);

            return((EntityDataSourceReferenceGroup)Activator.CreateInstance(groupType, new object[] { end }));
        }
        internal EntityDataSourceWrapperPropertyDescriptor(EntityDataSourceWrapperCollection collection, EntityDataSourceColumn column)
            : base(EntityDataSourceUtil.CheckArgumentNull(column, "column").DisplayName, new Attribute[] { })
        {
            EntityDataSourceUtil.CheckArgumentNull(collection, "collection");

            _collection = collection;
            _column     = column;
        }
Ejemplo n.º 8
0
        internal static EntityDataSourceReferenceValueColumn Create(Type clrToType, MetadataWorkspace ocWorkspace, NavigationProperty navigationProperty)
        {
            EntityDataSourceUtil.CheckArgumentNull(clrToType, "clrToType");

            Type columnType = typeof(EntityDataSourceReferenceValueColumn <>).MakeGenericType(clrToType);
            EntityDataSourceReferenceValueColumn result = (EntityDataSourceReferenceValueColumn)Activator.CreateInstance(columnType, ocWorkspace, navigationProperty);

            return(result);
        }
Ejemplo n.º 9
0
        Parameter _parameter; // Can be null, that's why this class doesn't subclass Parameter

        internal WebControlParameterProxy(string propertyName, ParameterCollection parameterCollection, EntityDataSource entityDataSource)
        {
            Debug.Assert(null != entityDataSource);
            Debug.Assert(!String.IsNullOrEmpty(propertyName));

            _parameter        = EntityDataSourceUtil.GetParameter(propertyName, parameterCollection);
            _collection       = parameterCollection;
            _entityDataSource = entityDataSource;
            VerifyUniqueType(_parameter);
        }
Ejemplo n.º 10
0
        private object Initialize(EntityDataSourceWrapper entity)
        {
            // get parent's value
            object parentObjectValue = GetParentObjectValue(entity, true /* initialize */);

            // construct type instance for this property
            object propertyValue = EntityDataSourceUtil.InitializeType(this.ClrType);

            // set property
            this.propertyInfo.SetValue(parentObjectValue, propertyValue, new object[] { });

            return(propertyValue);
        }
Ejemplo n.º 11
0
        internal EntityDataSourceWrapper(EntityDataSourceWrapperCollection collection, object trackedEntity)
        {
            EntityDataSourceUtil.CheckArgumentNull(collection, "collection");
            EntityDataSourceUtil.CheckArgumentNull(trackedEntity, "trackedEntity");

            this._collection = collection;

            // retrieve state entry
            if (!this._collection.Context.ObjectStateManager.TryGetObjectStateEntry(trackedEntity, out _stateEntry))
            {
                throw new ArgumentException(Strings.ComponentNotFromProperCollection, "trackedEntity");
            }
        }
Ejemplo n.º 12
0
 private static void AddReferenceNavigationColumns(List <EntityDataSourceColumn> columns, MetadataWorkspace ocWorkspace, EntitySet entitySet, EntityType entityType)
 {
     foreach (AssociationSetEnd toEnd in GetReferenceEnds(entitySet, entityType, /*forKey*/ false))
     {
         // Check for a navigation property
         NavigationProperty navigationProperty;
         if (TryGetCorrespondingNavigationProperty(toEnd.CorrespondingAssociationEndMember, out navigationProperty))
         {
             Type clrToType = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, navigationProperty);
             EntityDataSourceReferenceValueColumn column = EntityDataSourceReferenceValueColumn.Create(clrToType, ocWorkspace, navigationProperty);
             columns.Add(column);
         }
     }
 }
        private EntityDataSourceWrapper GetWrapper(object component)
        {
            // Validate that the component comes from the collection to which
            // this descriptor is bound. Elements of the collection are
            // non-null wrappers instances.
            EntityDataSourceUtil.CheckArgumentNull(component, "component");

            EntityDataSourceWrapper wrapper = component as EntityDataSourceWrapper;

            if (null == wrapper || this._collection != wrapper.Collection)
            {
                throw new ArgumentException(Strings.ComponentNotFromProperCollection, "component");
            }

            return(wrapper);
        }
Ejemplo n.º 14
0
        internal EntityDataSourceMemberPath(MetadataWorkspace ocWorkspace, EntityDataSourceMemberPath parent, EdmProperty property, bool isLocallyInteresting)
        {
            EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace");
            EntityDataSourceUtil.CheckArgumentNull(property, "property");

            this.property             = property;
            this.parent               = parent;
            this.isLocallyInteresting = isLocallyInteresting;
            this.clrType              = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, property);
            this.isKey = IsPropertyAKey(property);

            // retrieve PropertyInfo (with respect to parent CLR type)
            StructuralType parentType    = property.DeclaringType;
            Type           parentClrType = EntityDataSourceUtil.GetClrType(ocWorkspace, parentType);

            this.propertyInfo = EntityDataSourceUtil.GetPropertyInfo(parentClrType, this.property.Name);
        }
Ejemplo n.º 15
0
        internal override string GetEntitySqlValue()
        {
            // syntax: NAVIGATE(it, _association_type_name_, _target_role_name_)._key_member_
            StringBuilder builder = new StringBuilder();

            builder.Append("NAVIGATE(");
            builder.Append(EntityDataSourceUtil.EntitySqlElementAlias);
            builder.Append(", ");
            builder.Append(EntityDataSourceUtil.CreateEntitySqlTypeIdentifier(this.Group.End.ParentAssociationSet.ElementType));
            builder.Append(", ");
            builder.Append(EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.Group.End.CorrespondingAssociationEndMember.Name));
            builder.Append(").");
            builder.Append(EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.keyMember.Name));
            string result = builder.ToString();

            return(result);
        }
Ejemplo n.º 16
0
        internal string GetEntitySqlValue()
        {
            // it.[member1].[member2]...
            string prefix;

            if (null != parent)
            {
                prefix = parent.GetEntitySqlValue();
            }
            else
            {
                prefix = EntityDataSourceUtil.EntitySqlElementAlias;
            }

            string eSql = prefix + "." + EntityDataSourceUtil.QuoteEntitySqlIdentifier(this.property.Name);

            return(eSql);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Verifies that the query's typeusage will not result in a polymorphic result.
        /// If the query would be restricted "is of only" using entityTypeFilter, then
        /// this check assumes the result will not be polymorphic.
        ///
        /// This method is only called if the user specifies EntitySetName and updates are enabled.
        ///
        /// Does nothing for RowTypes.
        /// </summary>
        /// <param name="typeUsage">The TypeUsage from the query</param>
        /// <param name="itemCollection"></param>
        /// <returns></returns>
        internal static void CheckNonPolymorphicTypeUsage(EntityType entityType,
                                                          ItemCollection ocItemCollection,
                                                          string entityTypeFilter)
        {
            CheckArgumentNull <ItemCollection>(ocItemCollection, "ocItemCollection");

            if (String.IsNullOrEmpty(entityTypeFilter))
            {
                List <EdmType> types = new List <EdmType>(EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, ocItemCollection, /*includeAbstractTypes*/ true));
                if (entityType.BaseType != null ||
                    types.Count() > 1 || entityType.Abstract)
                {
                    throw new InvalidOperationException(Strings.EntityDataSourceUtil_EntityQueryCannotReturnPolymorphicTypes);
                }
            }

            return;
        }
Ejemplo n.º 18
0
        internal EntityDataSourceWrapperCollection(ObjectContext context, EntitySet entitySet, EntityType restrictedEntityType)
        {
            EntityDataSourceUtil.CheckArgumentNull(context, "context");
            EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet");

            _context     = context;
            _wrapperList = new List <EntityDataSourceWrapper>();

            // get handles on the relevant workspaces
            MetadataWorkspace csWorkspace = ((EntityConnection)context.Connection).GetMetadataWorkspace();
            MetadataWorkspace ocWorkspace = context.MetadataWorkspace;

            // if no restricted type is given, we assume the entity set element type is exposed
            EntityType entityType = restrictedEntityType ?? entitySet.ElementType;

            _clrEntityType = EntityDataSourceUtil.GetClrType(ocWorkspace, entityType);

            // if no restricted type is given and the set is polymorphic, make the collection readonly
            if (null == restrictedEntityType &&
                1 < EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, csWorkspace.GetItemCollection(DataSpace.CSpace), true).Count())
            {
                _isReadOnly = true;
            }

            // gather the properties
            ReadOnlyCollection <EntityDataSourceColumn> columns  = EntityDataSourceUtil.GetNamedColumns(csWorkspace, ocWorkspace, entitySet, entityType);
            List <PropertyDescriptor> visiblePropertyDescriptors = new List <PropertyDescriptor>(columns.Count);
            List <EntityDataSourceWrapperPropertyDescriptor> propertyDescriptors = new List <EntityDataSourceWrapperPropertyDescriptor>(columns.Count);

            foreach (EntityDataSourceColumn column in columns)
            {
                var descriptor = new EntityDataSourceWrapperPropertyDescriptor(this, column);
                propertyDescriptors.Add(descriptor);

                // if the descriptor does not have a dependent, it is exposed to the user
                if (!descriptor.Column.IsHidden)
                {
                    visiblePropertyDescriptors.Add(descriptor);
                }
            }

            _visiblePropertyDescriptors = new PropertyDescriptorCollection(visiblePropertyDescriptors.ToArray(), true);
            AllPropertyDescriptors      = propertyDescriptors.AsReadOnly();
        }
Ejemplo n.º 19
0
        internal EntityDataSourceReferenceKeyColumn(MetadataWorkspace workspace, EntityDataSourceReferenceGroup group, EdmProperty keyMember, EntityDataSourceColumn dependent)
            : base(CreateDisplayName(group, keyMember), dependent)
        {
            EntityDataSourceUtil.CheckArgumentNull(group, "group");
            EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember");
            Debug.Assert(EntityDataSourceUtil.IsScalar(keyMember.TypeUsage.EdmType), "Expected primitive or enum type for key members.");

            this.group     = group;
            this.keyMember = keyMember;
            this.clrType   = EntityDataSourceUtil.GetMemberClrType(workspace, keyMember);

            // if the association end is optional (0..1), make sure the CLR type
            // is also nullable
            if (this.group.End.CorrespondingAssociationEndMember.RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne)
            {
                this.clrType    = EntityDataSourceUtil.MakeNullable(clrType);
                this.isNullable = true;
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Get the Clr type for the primitive enum or complex type member. The member must not be null.
        /// </summary>
        internal static Type GetMemberClrType(MetadataWorkspace ocWorkspace, EdmMember member)
        {
            EntityDataSourceUtil.CheckArgumentNull(member, "member");

            EdmType memberType = member.TypeUsage.EdmType;

            Debug.Assert(EntityDataSourceUtil.IsScalar(memberType) ||
                         memberType.BuiltInTypeKind == BuiltInTypeKind.ComplexType ||
                         memberType.BuiltInTypeKind == BuiltInTypeKind.EntityType, "member type must be primitive, enum, entity or complex type");

            Type clrType;

            if (EntityDataSourceUtil.IsScalar(memberType))
            {
                clrType = memberType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType ?
                          ((PrimitiveType)memberType).ClrEquivalentType :
                          GetClrType(ocWorkspace, (EnumType)memberType);

                if (!NullCanBeAssignedTo(clrType))
                {
                    Facet facet;
                    if (member.TypeUsage.Facets.TryGetValue("Nullable", true, out facet))
                    {
                        if ((bool)facet.Value)
                        {
                            clrType = MakeNullable(clrType);
                        }
                    }
                }
            }
            else
            {
                Debug.Assert(
                    memberType.BuiltInTypeKind == BuiltInTypeKind.EntityType || memberType.BuiltInTypeKind == BuiltInTypeKind.ComplexType,
                    "Complex or Entity type expected");

                clrType = GetClrType(ocWorkspace, (StructuralType)memberType);
            }

            return(clrType);
        }
Ejemplo n.º 21
0
        private void AppendOrderByKey(StringBuilder orderByClauseBuilder, string expression, string errorText, TypeUsage tu)
        {
            if (!String.IsNullOrEmpty(expression))
            {
                string[] statements = expression.Split(',');

                string spacer = String.Empty;
                foreach (string statement in statements)
                {
                    bool   isAscending = true;
                    string columnName  = ParseStatement(statement.Trim(), out isAscending);

                    if (String.IsNullOrEmpty(columnName))
                    {
                        throw new ArgumentException(Strings.EntityDataSourceView_EmptyPropertyName);
                    }

                    if (EntityDataSourceUtil.PropertyIsOnEntity(columnName, _wrapperCollection, null, tu))
                    {
                        orderByClauseBuilder.Append(spacer);
                        orderByClauseBuilder.Append(EntityDataSourceUtil.GetEntitySqlValueForColumnName(columnName, _wrapperCollection));
                    }
                    else // pass the sort expression through verbatim.
                    {
                        if (!columnName.StartsWith("it.", StringComparison.OrdinalIgnoreCase))
                        {
                            columnName = "it." + columnName;
                        }
                        orderByClauseBuilder.Append(spacer + columnName);
                    }

                    if (!isAscending)
                    {
                        orderByClauseBuilder.Append(c_esqlDescendingTail);
                    }

                    spacer = ",";
                }
            }
        }
Ejemplo n.º 22
0
        private static string GenerateDefaultOrderByFromTypeUsage(TypeUsage tu)
        {
            StringBuilder orderByBuilder = new StringBuilder();
            ReadOnlyMetadataCollection <EdmProperty> propertyCollection;
            List <string> keyMemberNames = null;
            EntityType    entityType     = tu.EdmType as EntityType;

            if (null != entityType)
            {
                ReadOnlyMetadataCollection <EdmMember> keyMembers;
                keyMembers         = entityType.KeyMembers;
                keyMemberNames     = new List <string>(entityType.KeyMembers.Count);
                propertyCollection = entityType.Properties;

                foreach (EdmMember edmMember in keyMembers)
                {
                    keyMemberNames.Add(edmMember.Name);
                }
            }
            else
            {
                return(String.Empty);
            }

            foreach (EdmProperty property in propertyCollection)
            {
                if (keyMemberNames.Contains(property.Name) && EntityDataSourceUtil.IsScalar(property.TypeUsage.EdmType))
                {
                    if (0 < orderByBuilder.Length)
                    {
                        orderByBuilder.Append(", ");
                    }
                    orderByBuilder.Append(EntityDataSourceUtil.EntitySqlElementAlias);
                    orderByBuilder.Append(".");
                    orderByBuilder.Append(EntityDataSourceUtil.QuoteEntitySqlIdentifier(property.Name));
                }
            }
            return(orderByBuilder.ToString());
        }
Ejemplo n.º 23
0
        private static string CreateDisplayName(EntityDataSourceReferenceGroup group, EdmProperty keyMember)
        {
            EntityDataSourceUtil.CheckArgumentNull(group, "group");
            EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember");

            NavigationProperty navigationProperty;

            string result;

            if (EntityDataSourceUtil.TryGetCorrespondingNavigationProperty(group.End.CorrespondingAssociationEndMember, out navigationProperty))
            {
                result = navigationProperty.Name + "." + keyMember.Name;
            }
            else
            {
                // if there is no Navigation property, use the TargetTole and KeyMember name
                // TargetRole.KeyMember
                result = group.End.Name + "." + keyMember.Name;
            }

            return(result);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Use this method to set the properties on the wrapped entity
        /// </summary>
        /// <param name="propertiesFromViewState"></param>
        /// <param name="wrapper"></param>
        /// <param name="overwriteSameValue"></param>
        internal void SetAllProperties(Dictionary <string, object> propertiesFromViewState, bool overwriteSameValue,
                                       ref Dictionary <string, Exception> propertySettingExceptionsCaught)
        {
            // We aggregate the reference descriptors rather than setting them directly
            // to account for compound keys (we need all components of the key to create
            // an EntityKey that can be set on the EntityReference)
            var referenceList = new List <KeyValuePair <EntityDataSourceReferenceKeyColumn, object> >();

            foreach (EntityDataSourceWrapperPropertyDescriptor descriptor in _collection.AllPropertyDescriptors)
            {
                // figure out which display name to match for this descriptor
                string displayName = descriptor.Column.DisplayName;

                // if we have a controlling column, use its display name instead
                if (descriptor.Column.ControllingColumn != null)
                {
                    displayName = descriptor.Column.ControllingColumn.DisplayName;
                }

                object value;
                if (propertiesFromViewState.TryGetValue(displayName, out value))
                {
                    // get all changed ReferencePropertyDescriptor from ViewState
                    EntityDataSourceReferenceKeyColumn referenceColumn = descriptor.Column as EntityDataSourceReferenceKeyColumn;

                    // convert the value as needed
                    object adjustedValue = EntityDataSourceUtil.ConvertType(value, descriptor.PropertyType, descriptor.DisplayName);

                    if (null != referenceColumn)
                    {
                        referenceList.Add(new KeyValuePair <EntityDataSourceReferenceKeyColumn, object>(
                                              referenceColumn, adjustedValue));
                        continue;
                    }

                    if (overwriteSameValue || adjustedValue != descriptor.GetValue(this))
                    {
                        if (EntityDataSourceUtil.NullCanBeAssignedTo(descriptor.PropertyType) || null != adjustedValue)
                        {
                            try
                            {
                                descriptor.SetValue(this, adjustedValue);
                            }
                            catch (Exception e)
                            {
                                // The property descriptor uses reflection to set the property. Therefore, the inner exception contains the actual message.
                                Exception exceptionToThrow = e;
                                if (e.InnerException != null)
                                {
                                    exceptionToThrow = e.InnerException;
                                }
                                if (null == propertySettingExceptionsCaught)
                                {
                                    propertySettingExceptionsCaught = new Dictionary <string, Exception>();
                                }
                                propertySettingExceptionsCaught.Add(descriptor.DisplayName, exceptionToThrow);
                            }
                        }
                    }
                }
            }

            // aggregate setting for EntityKey
            SetEntityKeyProperties(referenceList, overwriteSameValue);
        }
Ejemplo n.º 25
0
 internal static string GetQualifiedEntitySetName(EntitySet entitySet)
 {
     EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet");
     // ContainerName.EntitySetName
     return(entitySet.EntityContainer.Name + "." + entitySet.Name);
 }
        protected EntityDataSourceReferenceGroup(AssociationSetEnd end)
        {
            EntityDataSourceUtil.CheckArgumentNull(end, "end");

            this.end = end;
        }
Ejemplo n.º 27
0
 internal EntityDataSourcePropertyColumn(EntityDataSourceMemberPath memberPath)
     : base(EntityDataSourceUtil.CheckArgumentNull(memberPath, "memberPath").GetDescription())
 {
     this.memberPath = memberPath;
 }