Hi,
I have followed Chris's Module Templates (great work btw) and am trying to work out the best way to hydrate an object using the new DAL2.
For example: I have an Info class that has a FromUserID on it. I need to show the DisplayName on the UI. I started off with these approaches:
1) I change the controller code to hit UserController and populate the display name. I am worried about this performance of this (I have FromUserId, ToUserId, changed and created UserID so this is 4 database hits, unless it is cached?
The 2nd approach would be to write a custom stored proc with a join to the User table. I don't like this approach as I am trying to reduce the number of stored procs I have for simple tasks.
The 3rd approach would be to use an inline SQL join statement. This is probably the best way as there won't be a performance hit and I can do it all in C#.
Opinions please?
eg:
public
DareInfo GetDare(
int
dareId,
bool
hydrate =
true
)
{
DareInfo dareInfo;
using
(IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<DareInfo>();
dareInfo = rep.GetById(dareId);
if
(hydrate)
{
UserInfo fromUserInfo = UserController.GetUserById(0, dareInfo.FromUserId);
UserInfo toUserInfo = UserController.GetUserById(0, dareInfo.FromUserId);
dareInfo.FromUserName = fromUserInfo.DisplayName;
dareInfo.ToUserName = toUserInfo.DisplayName;
}
}
return
dareInfo;
}
On another note: I was debating the 2 ways to handle the fields in the Info object:
1) Inherit the Info object and add the FromDisplayName property and call it InfoHydrated.
2) Add the FromDisplayName property with an [IgnoreColumn] attribute.
I think the 2nd option is cleaner - opinions?