I'd like to move my initialization of database tables and data (user, user in role e.t.c.) in Configuration.cs like in this article: http://blog.longle.net/2012/09/25/seeding-users-and-roles-with-mvc4-simplemembershipprovider-simpleroleprovider-ef5-codefirst-and-custom-user-properties/
But i have a question: is it possible to set up UserId of adding users? I mean, i could add 5 users, and, as i think, they should get 1-2-3-4-5 Ids, but could i controll it and set up their Ids manual?
Now initialization looks like:
if (!WebSecurity.UserExists("elena"))
WebSecurity.CreateUserAndAccount("elena", "password");
Yes, you would do this by passing in the properties to set. For example:
WebSecurity.CreateUserAndAccount("elena", "password", new { UserId = 1 });
Of course, you would need to make sure the UserId column was not set to be an identity column, and you would have to change your UsersContext schema to add that as well.
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int UserId { get; set; }
public string UserName { get; set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With