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
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