简体   繁体   中英

Conflicting changes to the role of Foo on relationship Bar error on UserManager.CreateAsync

Ok, I see a number of other questions regarding the Entity Framework "Conflicting changes to the role of Foo on relationship Bar" error, and the answers all seem to revolve around changing the code that is interacting with the database.

I can't do that here, as I am getting this error on UserManager.CreateAsync , so I need to change my models.

The exact error message is below:

Conflicting changes to the role 'ApplicationUser_Customer_Target' of the relationship 'Myproject.Models.ApplicationUser_Customer' have been detected.

Ok so here is ApplicationUser:

public class ApplicationUser : IdentityUser
{
    private CustomerModel _customer;

    public CustomerModel Customer
    {
        get
        {
            return _customer ?? new CustomerModel();
        }
        set { _customer = value; }
    }
}

And here is CustomerModel:

public sealed class CustomerModel
{
    public string Id { get; set; }
}

I created a migration for this, and updated the database using the Updte-Database method.

Here is a screenshot of SQL Server Management studio:

屏幕快照显示关系

I am completely baffled by this, what am I doing wrong here?

Thanks

I struggled with this for an hour before I asked this question, and then I solved it instantly.

To make another part of the code work, I was returning an instance of Customer if the private backing field was null in ApplicationUser.

This was causing the CreateUser method to fall over and die.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM