views:

21

answers:

2

I've asked this before but I'm resurrecting it because I didn't get a satisfactory response.

I have a profile variable, and when I load it then it is assigned default values. I need to check to see if it has ever been assigned. Typically I'd use an is null comparison but that won't work.

It was suggested I use the FindProfilesByUserName which seems backward. Regardless this method wont work as it only tells me if the user has any profile created but not for the specific member data I'm interested in. (It seems backwards because the whole purpose of the profiles was to make it easy to access the current user profile data. This seems like a bad design unless I'm missing something.)

The last option I can see is assigning bits to every object to see if they were dirtied or set. I don't want to do this unless required though.

Here is the FindProfilesByUserName sample :

ProfileInfoCollection profileInfo = ProfileManager.FindProfilesByUserName(ProfileAuthenticationOption.All, Membership.GetUser().UserName);
        if (profileInfo.Count > 0)
        {
            if (profileInfo[Membership.GetUser().UserName] != null)

One last idea I've had is storing collections because I think I've read they are nullable. In my case I don't really need a collection but that might be the easiest solution. Look forward to suggestions.. I feel like I must be missing something obvious on this matter.

To be clear

this doesn't work (if http.context.profile.mydata != null)

A: 

Okay, I'm surprised no one has experienced this problem: makes me think I'm missing something basic. I'm going to add a group and a dirty flag for the group. If anyone can provide another solution I will give credit for the answer. Or a dirtied flag to the object..

Curtis White
A: 

Simply set a default value that represents null. e.g. for an int field, set default to -1.

The requirement that you are describing is, in my opinion, an edge case and in any case is easily fulfilled using the strategy described above.

Your assertion that it is an oversight or shortcoming of the profile model is premature, i think.

Good luck.

Sky Sanders
@Code This is a fairly big oversight because it forces a non necessary model on any objects/classes you want to store. Sure, there are fixes.
Curtis White