Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTO and properties

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have my own data types for use with a database that have various properties to manipulate values such as:

Data: current value
First: original value
IsNull: is the current state null (no value in Data)
IsFirstNull: was the initial state of the object null
Changed: has the value changed since the initial value was set.
SetNull(): set the object to null
SetFirstNull: set the initial value to null
Reset: set values all to original settings.

Each one of the objects has these. There is an object for each type of standard variables, such as:

int – IntType
string – StringType
bool – BoolType

These would go in my DTO.

I set up these types to handle the different states of each variable I read from a table as well as handle nulls. It was always hard to tell whether a value was null or not or whether it was null when the value was originally read so I would know how to write it back or whether the value was changed. Sometimes you need to know what the original value was when you read the data from the table.

So I only use these for data I have read from my tables.

I wanted to put them in a DTO but can’t decide whether to set up properties to access these variables or to access them directly. Here is a sample of a DTO (with properties):

Code:
public class LoginDTO
{
    public IntType loginID = new IntType();
    public StringType userName = new StringType();

    #region Properties

    public object LoginID
    {
        get
        {
            object value = null;
            return NullHandler.SetDbObjectValueFromValue(loginID, ref value);
        }
        set
        {
            NullHandler.GetValueFromDbObject(value, ref loginID);
        }
    }

    public object UserName
    {
        get
        {
            object value = null;
            return NullHandler.SetDbObjectValueFromValue(userName, ref value);
        }
        set
        {
            NullHandler.GetValueFromDbObject(value, ref userName);
        }
    }

To access the class, I could do something like

loginDto.userName.Data
or
if (loginDto.userName.IsNull)…
or
loginDto.userName.First

I can’t really set up a property to UserName.IsNull (I don’t think) where I would just return username.IsNull.

Seems like setting up properties is a little overkill since I already have the properties setup inside the objects with their own memory variables.

But not sure if that would be against rules of using a DTO.

Just trying to get some opinions on this as I am setting up templates to build my DTO’s and want to standardize them.

Thanks,

Tom



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top