I'm trying to create a new user when receiving a POST
request to api/accounts/
in my asp.net web-api 2 project.
Attempt 1: Create Identity User
I've tried exactly as it was shown in the project template:
// Inside Post() method
IdentityUser newUser = new IdentityUser()
{
UserName = "username",
};
IdentityResult result = await this.UserManager.CreateAsync(newUser, "password");
System.Data.Entity.Core.UpdateException: Cannot insert the value NULL into column 'Discriminator', table 'MyDb.dbo.AspNetUsers'; column does not allow nulls. INSERT fails.\\r\\nThe statement has been terminated.
Attempt 2: Create a User
I've also tried adding my subclassed version of IdentityUser
:
// Definition
public class User : IdentityUser
{
public User() { }
}
// Inside Post() method
User newUser = new User()
{
UserName = userDto.Email,
};
IdentityResult result = await this.UserManager.CreateAsync(newUser, "password");
System.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'MyProject.Data.User'.
It was working originally and I can't figure out why it isn't anymore. Originally I added two fields onto my User object (FirstName, Lastname) but I still have the problem after removing them.
对于asp身份2.2,Discriminator列已删除表单数据库,您可以迁移数据库或只是删除列
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.