I am using ASP.NET DynamicData (based on LINQ to SQL) on my site for basic scaffolding. On one table I have added additional properties, that are not stored in the table, but are retrieved from somewhere else. (Profile information for a user account, in this case).
They are displayed just fine, but when editing these values and pressing "Update", they are not changed.
Here's what the properties look like, the table is the standard aspnet_Users table:
public String Address
{
get
{
UserProfile profile = UserProfile.GetUserProfile(UserName);
return profile.Address;
}
set
{
UserProfile profile = UserProfile.GetUserProfile(UserName);
profile.Address = value;
profile.Save();
}
}
When I fired up the debugger, I've noticed that for each update the set
accessor is called three times. Once with the new value, but on a newly created instance of user, then once with the old value, again on an new instance, and finally with the old value on the existing instance.
Wondering a bit, I checked with the properties created by the designer, and they, too, are called three times in (almost) the same fashion. The only difference is, that the last call contains the new value for the property.
I am a bit stumped here. Why three times, and why are my new properties behaving differently? I'd be grateful for any help on that matter! =)