I set all fields to types with null values, where the database database fields correspond to null values. Good? Bad?
Long version:
This works fine, I just feel like I can abuse that I can make the material null.
This is basically an internal employee management application that is linked to our SQL database. I use a three-layer structure: from presentation to database: business objects β business logic β data access.
For my Employee object, I have the following fields:
public class Employee : Person { private EmployeeTitle? _employeeTitle = null; //enum private EmployeeType _employeeType; //enum private DateTime _startDate; private DateTime? _endDate = null; private EmployeeInsuranceRecord _employeeInsuranceRecord = new EmployeeInsuranceRecord(); //... } public class EmployeeInsuranceRecord { private int? _employeeInsuranceRecordID = null; private string _alienRegistrationNumber = null; private string _healthInsuranceNumber = null; private string _unemploymentInsuranceNumber = null; private string _welfarePensionNumber = null; private DateTime? _insuranceAcquiredDate = null; //... }
And in my database:
EmployeeTitleID allows null. For example, an employee can start in a trial period without a given job name.
EmployeeTypeID does NOT allow null. Even if the employee is a guest or during the trial period, he must be explicitly selected for the purpose of recording.
StartDate does NOT allow null. If someone enters the database, we need to know when they started.
However, EndDate allows null. Anyone who is currently working does not yet have EndDate.
I create an instance of the EmployeeInsuranceRecord object for the Employee instance, but each field inside the EmployeeInsuranceRecord is NULL because the EmployeeInsuranceRecords goes into a separate table associated with the identifier, so an Employee can exist without an EmployeeInsuranceRecord (usually for people just starting out, still in the process of initial work ) By creating an instance of EmployeeInsuranceRecord using get-go, I can save the presentation layer cleaner without instantiating any classes. This does not affect performance, given the small scale we work with.
source share