E
E
embiid2021-05-17 11:47:12
ASP.NET
embiid, 2021-05-17 11:47:12

What is the problem with entity creation?

I'm creating a purchase for a web app. I have User, Order, OrderDetails, Product.
The problem is that when creating a migration, I get an error:

The property 'UserId' cannot be removed from entity type 'ShoppingCart.Domain.Entities.Order' because it is being used in the foreign key {'UserId'} on 'ShoppingCart.Domain.Entities.Order'. All containing foreign keys must be removed or redefined before the property can be removed.


public class Order
    {
        public int Id { get; set; }

        public string City { get; set; }

        public string Country { get; set; }

        public int ZipCode { get; set; }

        public User UserId { get; set; }

        public IList<OrderDetail> OrderDetails { get; set; }
    }

public class User
    {
        public int Id { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Email { get; set; }

        public string Phone { get; set; }

        public string Role { get; set; }

        public byte[] PasswordHash { get; set; }

        public byte[] PasswordSalt { get; set; }

        public IList<Order> Orders { get; set; }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-05-17
@embiid

in the Order class, for good, should not public User UserId { get; set; }be

public int UserId { get; set; }
public User User { get; set; }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question