views:

41

answers:

1

I created a class that extends ProfileBase:

public class CustomerProfile : ProfileBase
{
    public int CustomerID { get; set; }


    public string CustomerName { get; set; }

    public static CustomerProfile GetProfile()
    {
        return Create(Membership.GetUser().UserName) as CustomerProfile;
    }

    public static CustomerProfile GetProfile(string userName)
    {
        return Create(userName) as CustomerProfile;
    }
}

If I do:

CustomerProfile p = CustomerProfile.GetProfile();
p.CustomerID = 1;
p.Save();

The next time I try to access the value for the current user, it is not 1, it is 0, so it appears it is not saving it in the database.

In my web.config file I have the following snippet:

<profile inherits="PortalBLL.CustomerProfile">
  <providers>
    <add name="CustomerProfile" type="System.Web.Profile.SqlProfileProvider" applicationName="/" connectionStringName="LocalSqlServer"/>
  </providers>
</profile>

I tried the following and it worked, I am curious why it doesn't save it using the automatic properties.

[SettingsAllowAnonymous(false)]
public int CustomerID
{
    get { return (int)base.GetPropertyValue("CustomerID");}
    set { base.SetPropertyValue("CustomerID",value);}
}
A: 

Hi Xaisoft,

If you look at the implementation of ProfileBase you will see that the de-/serialization and storing of the values gets done in there. It privately holds a collection with the property information and how it gets serialized.

Michael

Michael Ulmann