开发者

Setting class properties quickly

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 se开发者_JAVA百科t properties 
        // which are coming from DB by extension method over context class?
        this = DAO.context.GetById<UserClass>(_iUser_id);
    }
    #endregion
}


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.


You could use a static method instead of a constructor:

public static UserClass GetById(int userId) {
    return DAO.context.GetById<UserClass>(userId);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜