Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Location
    Slovenia
    Posts
    3

    Question Custom objects or datasets ??

    Hello

    I'm using SQL 2000 server and ADO.NET (C#) and I have a problem. Since I'm not very experienced in database design, I dont know which solution is beter. Is it better to create custom object with fileds conaining data from tablet and design bussines logic around those fields, or use dtataset directly. I'll give an example. Let say I have to tables A and B. There is one-to-many relationship between them (for every row in A there are more rows in B). Is it better to create object for every row in A and object for every row in B and so every object for A has a collection of objects from table B with methods supporting data form table A and B. or is it better to create one object, that has two datasets A and B. There is quite a lot of bussines logic and methods for data maniupulation, besides rows from table B are often used without connection to table A, so I'm not sure which solution is better. If anybody had similar problems, I would be very grateful for help.

    Example:
    1.)
    class A
    {
    data fields for table A;
    Colections_of_B bb;
    varius methods ....;
    }

    class B
    {
    data fields from table B;
    varius methods ...;
    }
    2.)
    class A
    {
    DataSet A; // data from table A:
    DataSet B; // data from table B:
    varius methods;
    }


    Thanks
    Matjaz

  2. #2
    Join Date
    Aug 2003
    Location
    Near Chicago, IL USA
    Posts
    5

    Re: Custom objects or datasets ??

    I know exactly the situation you're in, because I've run into it a number of times myself, including today. I use Sybase SQL Anywhere and VB.NET, but the concept is the same. What I usually do in order to reduce the memory and DB access load is the following:

    Create an object for the rows in Table A. This class should contain A's primary key, any additional info for A, and an array for the identifier from table B. You also write a class for rows from Table B. Then, you just select the ID from table B initially, and when you need to perform operations on B items, you can select an ArrayList of B objects as a local variable. This way, you're not keeping the entire collection / arraylist of B objects and passing it around. It requires working in a connected environment, since you have to be able to select relevant information about the B objects after the initial connection. This also allows you to still have a B object available for when you use B items independent of A.

    What I have is a basic DB object that has two fields:

    ID (Object)
    Description (String)

    Since by far the most common operation is selecting an identifier with a string description, it's easy to re-use this object for various purposes. You can also derive classes from this one to add fields and specific methods. I have a number of classes that have a similar structure to this one but with maybe different data types or an additional field or two.

    The best part is that using constructors it's easy to get the Description field (or some equivalent) by passing in the identifier and having a property that automatically selects the other field or fields. You can derive a Collection-type class that selects all of the additional fields at once and then fills the B (or A) object with that data (i.e. "SELECT ID, Description From B Where ID IN (" & Join(BObjIDToStringArray,",") & ")".

    I hope this answers your question. If not, let me know and I'll try again.

    Mike


    Originally posted by MatjazP
    Hello

    I'm using SQL 2000 server and ADO.NET (C#) and I have a problem. Since I'm not very experienced in database design, I dont know which solution is beter. Is it better to create custom object with fileds conaining data from tablet and design bussines logic around those fields, or use dtataset directly. I'll give an example. Let say I have to tables A and B. There is one-to-many relationship between them (for every row in A there are more rows in B). Is it better to create object for every row in A and object for every row in B and so every object for A has a collection of objects from table B with methods supporting data form table A and B. or is it better to create one object, that has two datasets A and B. There is quite a lot of bussines logic and methods for data maniupulation, besides rows from table B are often used without connection to table A, so I'm not sure which solution is better. If anybody had similar problems, I would be very grateful for help.

    Example:
    1.)
    class A
    {
    data fields for table A;
    Colections_of_B bb;
    varius methods ....;
    }

    class B
    {
    data fields from table B;
    varius methods ...;
    }
    2.)
    class A
    {
    DataSet A; // data from table A:
    DataSet B; // data from table B:
    varius methods;
    }


    Thanks
    Matjaz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •