BLL / Data Access RRS feed

  • Question

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

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

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

    Sunday, June 13, 2010 1:46 PM


  • User197322208 posted

    You can have UserProfile class(with Users and Profile members) to load both User and profile from a simple call

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 13, 2010 6:47 PM