User-265234229 posted
Im wondering what the best approach for the following would be,
I have two objects, Users and Profile. I am using a 3tier design and i have the following code (shortened)
//BLL
public class Users
{
//..misc properties / methods / constructors
public Profile UserProfile {get; set;}
public bool InserUser()
{
int id = dal.InsertUser(this);
return this.UserProfile.InsertUser(this.UserProfile, id);
}
}
//DAL
public class UsersDal
{
int InsertUser(Users users)
{
//Insert only the Users table, or profile as well?
}
}
Now to my question. In my Users object i have defined methods for accessing User related information and in my Profile object i have methods for accessing profile information based off the users id.
For example, if i wanted to insert a new User i would do the following:
User.InsertUser(this);
User.UserProfile.InsertProfile(this.UserProfile, int userID);
Is this the better approach then to do it all in one query in the Users dal? The way im seeing it, im doing double the queries for virtually all user / profile related routines.
Getting a user and profile would require 2 sql calls instead of adding a simple inner join on the profile table.
Any thoughts?