INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

DTO and properties

DTO and properties

(OP)
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



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close