tags:

views:

27

answers:

2

class UserClass{

    #region Class properties which are binding from DB
    .
    .
    .
    #endregion


    #region Constructor Methods
    public UserClass(int _iUser_id)
    {
        // of course this is wrong but how can i quickly set properties 
        // which are coming from DB by extension method over context class?
        this = DAO.context.GetById<UserClass>(_iUser_id);
    }
    #endregion
}
+2  A: 

You need to set the properties manually.

If you really want to, you could use reflection or expression trees to loop through the properties, but it's probably not worth it.

SLaks
Yes, it is very much code for this aim. Even it would be reusable.
uzay95
A: 

You could use a static method instead of a constructor:

public static UserClass GetById(int userId) {
    return DAO.context.GetById<UserClass>(userId);
}
Matti Virkkunen
Thank you for your answer. It is good, at least we have one way ;)
uzay95