I have 2 related issues. I inherited from ProfileBase and I have a couple of properites as such
public SomeType PropertyName
{
get { return (SomeType)base["PropertyName"]; }
set { base["PropertyName"] = value; Save(); }
}
I also have a User class (UserId, UserName, Profile, LastActivityDate) that has 2 additional properties out of the profile that I retrieve in my View to show a list of Users (i.e. @Model.Profile.PropertyName).
However, everytime I access a property (from my View) it seems to update the LastActivityDate in the aspnet_Users table because when I show the LastActivityDate as well as the profile properties on my screen the LastActivtyDate is out of sync with the database.
Also there is a LastActivityDate property available in my profile which unfortunately is not available and is in fact set to null and throws an exception when accessing it saying the property UserName is null. So the static Create method provided by ProfileBase seems to retrieve the correct profile properties but does not set the base's UserName property even though you pass in a UserName parameter to the Create method. Is this a internal bug? I was kind of hoping if by accessing the property because the LastActivityDate is updated then I could store that value to update my LastActivityDate in my User class before it is rendered to the page. The only way I can think of doing it is:
public SomeType PropertyName
{
get
{
SomeType result = (SomeType)base["PropertyName"];
OnLastActivityDateChanged();
return result;
}
set { base["PropertyName"] = value; }
}
then in my User class:
...
public MyProfile()
{
Profile.LastActivityDateChanged += Profile_LastActivityDateChanged();
}
~MyProfile()
{
Profile.LastActivityDateChanged -= Profile_LastActivityDateChanged();
}
...
void Profile_LastActivityDateChanged(object sender, EventArgs e)
{
//Run a query to get the latest LastActivityDate
this.LastActivityDate = ...
}
It seems I have to make 1 call to retrieve the full list to my aspnet_Users table then another call for each row just to get the latest activity date. ARGGGGHHH!!!
Am I going about this the wrong way!
I put an ajax refresh hyperlink next to each User row and when I click it, immediately after loading the page, the value changes. Therefore my suspision is valid that calling a property via the inherited profilebase class updates the value. Is there a workaround? It is a bit miss leading when my page says User Smith has no activity for 4 days then I click my ajax refresh link (or refresh the whole page for that matter) and now it says Smith was active but it was just me meally showing the page that indirectly caused an activity read event.