开发者

CustomProfile is not saving?

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;
    }

    pub开发者_JAVA技巧lic 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);}
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜