3

I'm trying to add expression,which changes boolean value of current column to string value, for DataColumn:

col = new DataColumn("isDirectionIn", typeof(string),
                                     "IIF(isDirectionIn = true, 'in', 'out')");

But I always get an ArgumentException: Cannot set Expression property due to circular reference in the expression.

What should I do to avoid this exception? Thank in advance.

Cris
  • 12,799
  • 5
  • 35
  • 50
Alekstim
  • 452
  • 1
  • 8
  • 19

1 Answers1

2

The error message is telling you clearly that you are referencing your Expression column in the calculation of you Expression column, thus a circular reference.

You need to do something like:

col = new DataColumn("isDirectionAsString", typeof(string),
                                     "IIF(isDirectionIn = true, 'in', 'out')");

In other words, you can't do that "in-place". You need an extra column for your "as string" value.

Cheers

Luc Morin
  • 5,302
  • 20
  • 39