I'm looking for advice on best practices here...
Data Tables:
Measurement
===========
measureId number
measureText varchar(50)
statusId number
Status
======
statusId number
statusText varchar(50)
Here are the two classes I need to define:
Measurement : BusinessBase<Measurement>
MeasurementInfo : ReadOnlyBase<MeasurementInfo>
Given that statusId is a meaningless computer-generated Id, it's pretty worthless as a value in a list of measurements (from a human understanding perspective). So my query (and thus the associated read only properties for MeasurementInfo would be:
select
m.measureId
,m.measureText
,m.statusId
,s.statusText
from Measurement as M
inner join Status as s on m.statusId = s.statusId
But what about the Measurement object?
Should I have a read-only property StatusText and a read-write property StatusId, where setting StatusId causes the StatusText property to be changed (after a quick query to the database)?
What have people found to be the cleanest and most productive course of action in this situation?
Should I include StatusText as a read-only property of Measurement? I'm sure to need it when a person takes a look at a detailed Measurement data entry/data review screen...
You might consider using a NameValueList named StatusOptions or something. Then Measurement can expose a read-write StatusId property and a read-only StatusText property - but your UI could use a combobox bound to StatusId and to the StatusOptions object - thus hiding the Id from the user while providing edit capabilities.
Measurement.StatusText is probably best implemented using StatusOptions too - as you'd want it to change as the StatusId changes:
public string StatusText
{
get {
return StatusOptions.GetOptions().Value(_statusId);
}
}
As long as you implement StatusOptions along the lines of RoleList from Chapter 8 (so it is cached) this is typically a good answer.
Copyright (c) Marimer LLC