D
David Benoff
Hi all,
I'm a java guy getting started with C#/.NET/ADO and working with strongly
typed datasets. I'm playing with this schema:
CATEGORIES 1-----0...* USERS 1-----0...* USERTEAM 0...*-----1 TEAMS
I created my four dataadapters, created a dataset, set up my datarelations,
make my calls to fill()....So far so good. From my user objects, I can
traverse the many-to-one relationship to get to the user's categories, and
traverse the many-to-many to get to the user's teams. But what do I do when
I only want one user, and his related objects? I don't want to call fill()
since that pulls back the complete contents of all the tables. The code
below does what I want but I'm hoping there's an easier way to do this....
String userSelect = String.Format("select users.* from users where userid =
{0}", id);
OdbcDataAdapter userDA = new OdbcDataAdapter(userSelect, odbcConnection1);
String categorySelect = String.Format("SELECT categories.* FROM categories
INNER JOIN users ON categories.categoryid = users.categoryid WHERE
users.userid = {0}", id);
OdbcDataAdapter categoryDA = new OdbcDataAdapter(categorySelect,
odbcConnection1);
String userteamSelect = String.Format("select userteam.* from userteam where
userid = {0}", id);
OdbcDataAdapter userteamDA = new OdbcDataAdapter(userteamSelect,
odbcConnection1);
String teamSelect = String.Format("SELECT teams.* FROM teams INNER JOIN
userteam ON teams.teamid = userteam.teamid WHERE userteam.userid = {0}",
id);
OdbcDataAdapter teamDA = new OdbcDataAdapter(teamSelect, odbcConnection1);
categoryDA.Fill(usersCategoriesDS1, "categories");
userDA.Fill(usersCategoriesDS1,"users");
teamDA.Fill(usersCategoriesDS1,"teams");
userteamDA.Fill(usersCategoriesDS1, "userteam");
Whew, that's a lot of work for a simple finder method! Do I really have to
write all this by hand? Is there some way to add criteria programmatically
to the default fill() method?
Any hints would be most appreciated,
David Benoff
I'm a java guy getting started with C#/.NET/ADO and working with strongly
typed datasets. I'm playing with this schema:
CATEGORIES 1-----0...* USERS 1-----0...* USERTEAM 0...*-----1 TEAMS
I created my four dataadapters, created a dataset, set up my datarelations,
make my calls to fill()....So far so good. From my user objects, I can
traverse the many-to-one relationship to get to the user's categories, and
traverse the many-to-many to get to the user's teams. But what do I do when
I only want one user, and his related objects? I don't want to call fill()
since that pulls back the complete contents of all the tables. The code
below does what I want but I'm hoping there's an easier way to do this....
String userSelect = String.Format("select users.* from users where userid =
{0}", id);
OdbcDataAdapter userDA = new OdbcDataAdapter(userSelect, odbcConnection1);
String categorySelect = String.Format("SELECT categories.* FROM categories
INNER JOIN users ON categories.categoryid = users.categoryid WHERE
users.userid = {0}", id);
OdbcDataAdapter categoryDA = new OdbcDataAdapter(categorySelect,
odbcConnection1);
String userteamSelect = String.Format("select userteam.* from userteam where
userid = {0}", id);
OdbcDataAdapter userteamDA = new OdbcDataAdapter(userteamSelect,
odbcConnection1);
String teamSelect = String.Format("SELECT teams.* FROM teams INNER JOIN
userteam ON teams.teamid = userteam.teamid WHERE userteam.userid = {0}",
id);
OdbcDataAdapter teamDA = new OdbcDataAdapter(teamSelect, odbcConnection1);
categoryDA.Fill(usersCategoriesDS1, "categories");
userDA.Fill(usersCategoriesDS1,"users");
teamDA.Fill(usersCategoriesDS1,"teams");
userteamDA.Fill(usersCategoriesDS1, "userteam");
Whew, that's a lot of work for a simple finder method! Do I really have to
write all this by hand? Is there some way to add criteria programmatically
to the default fill() method?
Any hints would be most appreciated,
David Benoff