public DataServiceAssociationProvider(AssociationDirection direction,
     ColumnProvider fromColumn, ColumnProvider toColumn, IList<String> foreignKeyNames) {
     Direction = direction;
     FromColumn = fromColumn;
     ToColumn = toColumn;
     ForeignKeyNames = new ReadOnlyCollection<string>(foreignKeyNames);
 }
		public DynamicDataAssociationProvider (AssociationDirection direction, ColumnProvider owner, ColumnProvider to)
		{
			this.Direction = direction;
			this.IsPrimaryKeyInThisTable = owner.IsPrimaryKey;
			this.FromColumn = owner;
			this.ToTable = to.Table;
		}
Esempio n. 3
0
		internal MetaColumn (MetaTable table, ColumnProvider provider)
		{
			Table = table;
			Provider = provider;
			Model = table.Model;
			HtmlEncode = true;

			Type columnType = ColumnType;
			TypeCode code = Type.GetTypeCode (columnType);
			TypeCode = code;
			switch (code) {
				case TypeCode.Single:
				case TypeCode.Double:
				case TypeCode.Decimal:
					IsFloatingPoint = true;
					break;

				case TypeCode.Byte:
				case TypeCode.Int16:
				case TypeCode.Int32:
				case TypeCode.Int64:
					IsInteger = true;
					break;

				case TypeCode.String:
					IsString = true;
					break;

				case TypeCode.Object:
					// So far only byte[] seems to be treated as a binary type
					if (columnType.IsArray && columnType.GetArrayRank () == 1 && columnType.GetElementType () == typeof (byte))
						IsBinaryData = true;
					break;

				default:
					TypeCode = TypeCode.Object;
					break;
			}

			IsLongString = MaxLength > SHORT_STRING_MAX_LENGTH;
		}
        protected static AttributeCollection AddDefaultAttributes(ColumnProvider columnProvider, AttributeCollection attributes) {
            List<Attribute> extraAttributes = new List<Attribute>();

            // If there is no required attribute and the Provider says required, add one
            var requiredAttribute = attributes.FirstOrDefault<RequiredAttribute>();
            if (requiredAttribute == null && !columnProvider.Nullable) {
                extraAttributes.Add(new RequiredAttribute());
            }

            // If there is no StringLength attribute and it's a string, add one
            var stringLengthAttribute = attributes.FirstOrDefault<StringLengthAttribute>();
            int maxLength = columnProvider.MaxLength;
            if (stringLengthAttribute == null && columnProvider.ColumnType == typeof(String) && maxLength > 0) {
                extraAttributes.Add(new StringLengthAttribute(maxLength));
            }

            // If we need any extra attributes, create a new collection
            if (extraAttributes.Count > 0) {
                attributes = AttributeCollection.FromExisting(attributes, extraAttributes.ToArray());
            }

            return attributes;
        }
 protected override MetaForeignKeyColumn CreateForeignKeyColumn(ColumnProvider columnProvider) {
     return new CustomMetaForeignKeyColumn(this, columnProvider);
 }
 internal void AddColumn(ColumnProvider cp) {
     _columns.Add(cp);
 }
 public override string GetSortExpression(ColumnProvider sortColumn)
 {
     return(GetSortExpression(sortColumn, "{0}.{1}"));
 }
Esempio n. 8
0
 public SecureMetaColumn(MetaTable table, ColumnProvider columnProvider)
     : base(table, columnProvider)
 {
 }
Esempio n. 9
0
		internal MetaForeignKeyColumn (MetaTable table, ColumnProvider provider)
			: base (table, provider)
		{
		}
Esempio n. 10
0
 /// <summary>
 /// Returns a string representing the sort expression that would be used for
 /// sorting the column represented by this association. The parameter is the
 /// property of the strongly typed entity used as the sort key for that entity.
 /// For example, assume that this association represents the Category column
 /// in the Products table. The sortColumn paramater is "CategoryName",
 /// meaning that this method is being asked to return the sort expression for
 /// sorting the Category column by the CategoryName property of the Category entity.
 /// The result sort expression would be "Category.CategoryName".
 /// The result of this method should be affected by whether the underlying data
 /// model is capable of sorting the entity by the given sort column (see
 /// ColumnProvider.IsSortable). The method can return a null value to indicate
 /// that sorting is not supported.
 /// </summary>
 /// <param name="sortColumn">the column to sort the entity by</param>
 /// <returns>the sort expression string, or null if sort is not supported for the
 /// given sort column</returns>
 public virtual string GetSortExpression(ColumnProvider sortColumn)
 {
     return(null);
 }
Esempio n. 11
0
 /// <summary>
 /// Instantiate a MetaForeignKeyColumn object. Can be overridden to instantiate a derived type 
 /// </summary>
 /// <returns></returns>
 protected virtual MetaForeignKeyColumn CreateForeignKeyColumn(ColumnProvider columnProvider) {
     return new MetaForeignKeyColumn(this, columnProvider);
 }
Esempio n. 12
0
        private MetaColumn CreateColumnInternal(ColumnProvider columnProvider) {
            if (columnProvider.Association != null) {
                switch (columnProvider.Association.Direction) {
                    case AssociationDirection.OneToOne:
                    case AssociationDirection.ManyToOne:
                        return CreateForeignKeyColumn(columnProvider);
                    case AssociationDirection.ManyToMany:
                    case AssociationDirection.OneToMany:
                        return CreateChildrenColumn(columnProvider);
                }
                Debug.Assert(false);
            }

            return CreateColumn(columnProvider);
        }
Esempio n. 13
0
 /// <summary>
 /// Instantiate a MetaColumn object. Can be overridden to instantiate a derived type 
 /// </summary>
 /// <returns></returns>
 protected virtual MetaColumn CreateColumn(ColumnProvider columnProvider) {
     return new MetaColumn(this, columnProvider);
 }
 internal void AddColumn(ColumnProvider cp)
 {
     DeleteColumnIfExists(cp.Name);
     _columns.Add(cp);
 }
 /// <summary>
 /// Returns a string representing the sort expression that would be used for
 /// sorting the column represented by this association. The parameter is the
 /// property of the strongly typed entity used as the sort key for that entity.
 /// For example, assume that this association represents the Category column
 /// in the Products table. The sortColumn paramater is "CategoryName",
 /// meaning that this method is being asked to return the sort expression for
 /// sorting the Category column by the CategoryName property of the Category entity.
 /// The result sort expression would be "Category.CategoryName".
 /// The result of this method should be affected by whether the underlying data
 /// model is capable of sorting the entity by the given sort column (see
 /// ColumnProvider.IsSortable). The method can return a null value to indicate
 /// that sorting is not supported.
 /// </summary>
 /// <param name="sortColumn">the column to sort the entity by</param>
 /// <returns>the sort expression string, or null if sort is not supported for the
 /// given sort column</returns>
 public virtual string GetSortExpression(ColumnProvider sortColumn) {
     return null;
 }
Esempio n. 16
0
 public virtual string GetSortExpression(ColumnProvider sortColumn)
 {
     throw new NotImplementedException();
 }
 public CustomMetaChildrenColumn(MetaTable table, ColumnProvider columnProvider) :
     base(table, columnProvider) {
 }
Esempio n. 18
0
		public virtual string GetSortExpression (ColumnProvider sortColumn)
		{
			throw new NotImplementedException ();
		}
Esempio n. 19
0
 protected override MetaColumn CreateColumn(ColumnProvider columnProvider)
 {
     return new SecureMetaColumn(this, columnProvider);
 }
 public MetaChildrenColumn(MetaTable table, ColumnProvider entityMember)
     : base(table, entityMember) {
 }
 public MetaForeignKeyColumn(MetaTable table, ColumnProvider entityMember)
     : base(table, entityMember) {
 }
        internal string GetSortExpression(ColumnProvider sortColumn, string format) {
            if (Direction == AssociationDirection.OneToMany || Direction == AssociationDirection.ManyToMany) {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                    "This association has direction {0} and does not support sorting.",
                    Direction));
            }

            if (sortColumn == null) {
                throw new ArgumentNullException("sortColumn");
            }

            if (!ToTable.Columns.Contains(sortColumn)) {
                throw new ArgumentException("The given sort column does not belong to this association&apos;s end table.", "sortColumn");
            }

            if (sortColumn.IsSortable) {
                return String.Format(CultureInfo.InvariantCulture, format, FromColumn.Name, sortColumn.Name);
            }
            else {
                return null;
            }
        }
Esempio n. 23
0
 public SecureMetaForeignKeyColumn(MetaTable table, ColumnProvider columnProvider)
     : base(table, columnProvider)
 {
 }
        internal string GetSortExpression(ColumnProvider sortColumn, string format)
        {
            if (Direction == AssociationDirection.OneToMany || Direction == AssociationDirection.ManyToMany) {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                    "DynamicDataResources.AssociationProvider_DirectionDoesNotSupportSorting",
                    Direction));
            }

            if (sortColumn == null) {
                throw new ArgumentNullException("sortColumn");
            }

            if (!ToTable.Columns.Contains(sortColumn)) {
                throw new ArgumentException("DynamicDataResources.AssociationProvider_SortColumnDoesNotBelongToEndTable", "sortColumn");
            }

            if (sortColumn.IsSortable) {
                return String.Format(CultureInfo.InvariantCulture, format, FromColumn.Name, sortColumn.Name);
            }
            else {
                return null;
            }
        }
 protected override MetaChildrenColumn CreateChildrenColumn(ColumnProvider columnProvider) {
     return new CustomMetaChildrenColumn(this, columnProvider);
 }
 public override string GetSortExpression(ColumnProvider sortColumn) {
     return GetSortExpression(sortColumn, "{0}.{1}");
 }
 public CustomMetaForeignKeyColumn(MetaTable table, ColumnProvider columnProvider) :
     base(table, columnProvider) {
 }