I
iambenb
Hi. In my app architecture, I have a common class library. One of the
things it does is to return a typed dataset with user information in.
The app passes the user identity, and the code queries a database that
holds more information on that user (telphone, email etc). So what I
want to do is to use the datarow of that dataset as a user object (I
know that there can only be one row per user).
I can do this fine by using the built in tableadapters, but what would
be really handy is if I could inherit the datarow itself, and set a
constructor with the username in.
Example of what I want:
public class UserObject : CommonData.Users.UsersRow {
public UserObject(string NtUserName) {
//Do something here that constructs the datarow from the
adaptor
}
}
I can't seem to inherit directly from the datarow, as I guess it was
never intended to be constructed directly like this. At the moment my
only working option is to create a custom object with the same
properties as the datarow, and set those properties myself, like this:
public class UserObject {
public UserObject(string NtUserName) {
CommonData.Users.UsersTableAdapter ta = new
CommonData.Users.UsersTableAdaptor;
ur = ta.GetDataByNtUserName(NtUserName)[0];
}
public int UserId {
get{ return ur.UserId; }
}
public string Email {
get{ return ur.Email; }
}
private CommonData.Users.UsersRow ur;
}
I don't mind using the second method, but feel like it's a waste
redefining properties that already exist in the datarow! Can anyone
think of a way I can do it with the first method?
Thanks.
things it does is to return a typed dataset with user information in.
The app passes the user identity, and the code queries a database that
holds more information on that user (telphone, email etc). So what I
want to do is to use the datarow of that dataset as a user object (I
know that there can only be one row per user).
I can do this fine by using the built in tableadapters, but what would
be really handy is if I could inherit the datarow itself, and set a
constructor with the username in.
Example of what I want:
public class UserObject : CommonData.Users.UsersRow {
public UserObject(string NtUserName) {
//Do something here that constructs the datarow from the
adaptor
}
}
I can't seem to inherit directly from the datarow, as I guess it was
never intended to be constructed directly like this. At the moment my
only working option is to create a custom object with the same
properties as the datarow, and set those properties myself, like this:
public class UserObject {
public UserObject(string NtUserName) {
CommonData.Users.UsersTableAdapter ta = new
CommonData.Users.UsersTableAdaptor;
ur = ta.GetDataByNtUserName(NtUserName)[0];
}
public int UserId {
get{ return ur.UserId; }
}
public string Email {
get{ return ur.Email; }
}
private CommonData.Users.UsersRow ur;
}
I don't mind using the second method, but feel like it's a waste
redefining properties that already exist in the datarow! Can anyone
think of a way I can do it with the first method?
Thanks.