2

How to get the value of EntityKey?

I tried:

String x = Customer.EntityKey.EntityKeyValues[0].Value;

String x = Customer.EntityKey.EntityKeyValues[0].Value.ToString();

String x = Customer.EntityKey.EntityKeyValues;

String x = Customer.EntityKey.EntityKeyValues.ToString();

Ended up with: Object reference not set to an instance of an object.

Please help. Thanks

noobplusplus
  • 177
  • 1
  • 2
  • 12

1 Answers1

3

As you reported that you're getting an Object reference not set to an instance of an object, you might want to check for a null reference;

String x = (Custormer == null ? null :
              Customer.EntityKey == null ? null :
                Customer.EntityKey.EntityKeyValues.Length == 0 ? null :
                  Customer.EntityKey.EntityKeyValues[0].Value);
Paulo Santos
  • 11,285
  • 4
  • 39
  • 65