Data tier with objects

  • Thread starter Alejandro Bibiano González
  • Start date
A

Alejandro Bibiano González

I have read Microsoft Desing Guides for the data tier and I'm trying to do a
User class to test it. I don't want to use directly dataset. I want to
isolate ADO.NET from outside the data tier.

I have do the user class:

public class User
{
private const int columnIdUser = 0;
private const int columnName = 1;

private DataSet ds = new DataSet();
private DataRow row = null;

public decimal IdUser
{
get { return (decimal)row[columnIdUser]; }
}

public string Name
{
get { return (string)row[columnName]; }
set { row[columnName] = value; }
}

public void Retrieve(decimal idUsuario)
{
SqlHelper.FillDataset(Global.ConectionString, CommandType.Text,
"SELECT USU_ID, USU_NAME FROM USU WHERE USU_ID = :idUsu", ds, new string[]
{"USU"}, new SqlParameter("idUsu", idUsu));
row = ds.Tables[0].Rows[0];
}
}

It works fine and I use it.:

User usu = new User();
usu.Retrieve(3);
Console.WriteLine(usu.IdUsu + " " + usu.Name);

But now I want implement a UserCollection/List that represent a colletion of
Users and I'dont know how to do it. The first aproach was to create a new
class inheritet from CollectionBase and Add "User" objects. With this
aproach I create a new dataset for every User and I think it isn't a good
idea.

¿How can I do a class like User (with Name and ID propoerty), but with a
collection of users stored in a single dataset (for performance reasons)?

Thanks
 
G

Guest

Alejandro
You can try couple of things to represent an instance of multiple user objects
As you said it has to be in some form a collection. It'll depend how you plan to use the collectio

Some suggestions
1. Array of User objects
2. Arraylist of User objects

A better approach would probably be to implement the icollection interface in .NET. This makes databinding easy. But sorting is a problem though

Click on the following link for a sample
http://samples.gotdotnet.com/quickstart/howto/doc/icollection.asp

HTH
Suresh

----- Alejandro Bibiano González wrote: ----

I have read Microsoft Desing Guides for the data tier and I'm trying to do
User class to test it. I don't want to use directly dataset. I want t
isolate ADO.NET from outside the data tier

I have do the user class

public class Use

private const int columnIdUser = 0
private const int columnName = 1

private DataSet ds = new DataSet()
private DataRow row = null

public decimal IdUse

get { return (decimal)row[columnIdUser];


public string Nam

get { return (string)row[columnName];
set { row[columnName] = value;


public void Retrieve(decimal idUsuario

SqlHelper.FillDataset(Global.ConectionString, CommandType.Text
"SELECT USU_ID, USU_NAME FROM USU WHERE USU_ID = :idUsu", ds, new string[
{"USU"}, new SqlParameter("idUsu", idUsu))
row = ds.Tables[0].Rows[0]



It works fine and I use it.

User usu = new User()
usu.Retrieve(3)
Console.WriteLine(usu.IdUsu + " " + usu.Name)

But now I want implement a UserCollection/List that represent a colletion o
Users and I'dont know how to do it. The first aproach was to create a ne
class inheritet from CollectionBase and Add "User" objects. With thi
aproach I create a new dataset for every User and I think it isn't a goo
idea

¿How can I do a class like User (with Name and ID propoerty), but with
collection of users stored in a single dataset (for performance reasons)

Thank
 
A

Alejandro Bibiano González

Thanks for your reply, but I alrredy know how to implementing the
collection. My problem is how to implement the collection of users using
only one dataset for all user objects in the collection, not one dataset per
user (the one used in the user object).

Any suggestions?



Suresh said:
Alejandro,
You can try couple of things to represent an instance of multiple user objects.
As you said it has to be in some form a collection. It'll depend how you plan to use the collection

Some suggestions:
1. Array of User objects.
2. Arraylist of User objects.

A better approach would probably be to implement the icollection interface
in .NET. This makes databinding easy. But sorting is a problem though.
Click on the following link for a sample.
http://samples.gotdotnet.com/quickstart/howto/doc/icollection.aspx

HTH,
Suresh.

----- Alejandro Bibiano González wrote: -----

I have read Microsoft Desing Guides for the data tier and I'm trying to do a
User class to test it. I don't want to use directly dataset. I want to
isolate ADO.NET from outside the data tier.

I have do the user class:

public class User
{
private const int columnIdUser = 0;
private const int columnName = 1;

private DataSet ds = new DataSet();
private DataRow row = null;

public decimal IdUser
{
get { return (decimal)row[columnIdUser]; }
}

public string Name
{
get { return (string)row[columnName]; }
set { row[columnName] = value; }
}

public void Retrieve(decimal idUsuario)
{
SqlHelper.FillDataset(Global.ConectionString, CommandType.Text,
"SELECT USU_ID, USU_NAME FROM USU WHERE USU_ID = :idUsu", ds, new string[]
{"USU"}, new SqlParameter("idUsu", idUsu));
row = ds.Tables[0].Rows[0];
}
}

It works fine and I use it.:

User usu = new User();
usu.Retrieve(3);
Console.WriteLine(usu.IdUsu + " " + usu.Name);

But now I want implement a UserCollection/List that represent a colletion of
Users and I'dont know how to do it. The first aproach was to create a new
class inheritet from CollectionBase and Add "User" objects. With this
aproach I create a new dataset for every User and I think it isn't a good
idea.

¿How can I do a class like User (with Name and ID propoerty), but with a
collection of users stored in a single dataset (for performance reasons)?

Thanks
 
M

Morten Mertner

I think you might benefit from the use of a persistence framework that
will automate what you are trying to do.

Check out http://www.mertner.com/projects/gentle for more information
and a few samples of how it works. It's very easy and allows you to work
with objects, completely shielding you from the ADO.NET layer.

Yours,
Morten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top