Reputation: 9352
I'm overriding asp.net membership provider with my custom membership provider. I would like to know what kind of type do I have to set for my ProviderUserKey in my User model?
I tried this:
public class User
{
[Key]
public ????? ProviderUserKey { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string PasswordQuestion { get; set; }
...
}
I don't know how to generate a new ProviderUserKey value when creating a new user. Any ideas?
Upvotes: 2
Views: 3401
Reputation: 11433
According to the virtual property, it should be
public Object ProviderUserKey { get; set; }
For your first question:
I would like to know what kind of type do I have to set for my ProviderUserKey in my User model?
From the MSDN page on the MemershipUser class:
The type of the identifier depends on the MembershipProvider or the MembershipUser. In the case of the SqlMembershipProvider, the ProviderUserKey can be cast as a Guid, since the SqlMembershipProvider stores the user identifier as a UniqueIdentifier.
So, it depends on how you're storing the user identifier (as an int / guid / varchar, etc). You type it as Object
, but cast it to the proper data type based on your implementation.
And your second question:
I don't know how to generate a new ProviderUserKey value when creating a new user. Any idea?
When you create the new user, and they are added to whatever you're storing them in (relational database, XML file, etc), retrieve the unique identifier generated by that process. If you are not generating a unique user identifier at that point...you need to be =)
Upvotes: 2