Question

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top