Ejemplo n.º 1
0
		internal void CompileExpression (string expression)
		{
			if (expression != String.Empty) {
				if (AutoIncrement || Unique)
					throw new ArgumentException ("Cannot create an expression on a column that has AutoIncrement or Unique.");

				if (Table != null) {
					for (int i = 0; i < Table.Constraints.Count; i++) {
						if (Table.Constraints [i].IsColumnContained (this))
							throw new ArgumentException (
								String.Format (
									"Cannot set Expression property on column {0}, because it is a part of a constraint.",
									ColumnName));
					}
				}

				Parser parser = new Parser ();
				IExpression compiledExpression = parser.Compile (expression);

				if (Table != null) {
					if (compiledExpression.DependsOn (this))
						throw new ArgumentException ("Cannot set Expression property due to circular reference in the expression.");
					// Check if expression is ok
					if (Table.Rows.Count == 0)
						compiledExpression.Eval (Table.NewRow ());
					else
						compiledExpression.Eval (Table.Rows [0]);
				}
				ReadOnly = true;
				_compiledExpression = compiledExpression;
			} else {
				_compiledExpression = null;
				if (Table != null) {
					int defaultValuesRowIndex = Table.DefaultValuesRowIndex;
					if (defaultValuesRowIndex != -1)
						DataContainer.FillValues (defaultValuesRowIndex);
				}
			}
		}