This question is locked. New answers and comments are not allowed.
Hi all,
I have two tables in my database that have an 1-1 weak relation: Customer and ContactPerson. This means ContactPerson table don't need to be filled.
I have created a class Customer with a Property ContactPerson
The problem is when I have a Customer without ContactPerson and I try to check for it, with the code below, I get a "NoSuchObjectException" on line 3.
I know I can get the Exception with a try-catch block but, as they say, "Exception handling are for cases you don't expect". In my case I'm expecting the ContactPerson sometimes not exists.
So, how can I avoid the "NoSuchObjectException" to be thrown?
Thanks.
I have two tables in my database that have an 1-1 weak relation: Customer and ContactPerson. This means ContactPerson table don't need to be filled.
I have created a class Customer with a Property ContactPerson
| namespace Example | |
| { | |
| [Persistent] | |
| public class ContactPerson | |
| { | |
| private String _FirstName; | |
| public String FirstName | |
| { | |
| get { return this._FirstName; } | |
| set { this._FirstName = value; } | |
| } | |
| } | |
| [Persistent] | |
| public class Customer | |
| { | |
| private ContactPerson _contactPerson; | |
| public ContactPerson ContactPerson | |
| { | |
| get { return this._contactPerson; } | |
| set { this._contactPerson = value; } | |
| } | |
| private String _TaxNumber; | |
| public String TaxNumber | |
| { | |
| get { return this._TaxNumber; } | |
| set { this._TaxNumber = value; } | |
| } | |
| } | |
| } | |
The problem is when I have a Customer without ContactPerson and I try to check for it, with the code below, I get a "NoSuchObjectException" on line 3.
| public static Boolean HasContactPerson(Customer customer) | |
| { | |
| if (customer.ContactPerson == null) | |
| return false; | |
| else | |
| return true; | |
| } | |
I know I can get the Exception with a try-catch block but, as they say, "Exception handling are for cases you don't expect". In my case I'm expecting the ContactPerson sometimes not exists.
So, how can I avoid the "NoSuchObjectException" to be thrown?
Thanks.