2

I have two tables: User and Order. User can be manager and client. Both of them must be in Order record. Here is the example of database. Database example

And entity framework (database first) generated for me following models:

public partial class User
{
    public User()
    {
        this.Orders = new HashSet<Order>();
        this.Orders1 = new HashSet<Order>();
    }

    public int UserID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string Phone { get; set; }

    public virtual ICollection<Order> Orders { get; set; }
    public virtual ICollection<Order> Orders1 { get; set; }
}

and

public partial class Order
{
    public Order()
    {
        this.LogEntries = new HashSet<LogEntry>();
    }

    public int OrderID { get; set; }
    public int ManagerID { get; set; }
    public int ClientID { get; set; }
    public System.DateTime OrderDate { get; set; }
    public System.DateTime ArrivalDate { get; set; }
    public System.DateTime DepartureDate { get; set; }
    public int OrderStatusID { get; set; }
    public decimal TotalPrice { get; set; }
    public Nullable<int> RoomID { get; set; }
    public int NumPlaces { get; set; }

    public virtual ICollection<LogEntry> LogEntries { get; set; }
    public virtual User User { get; set; }
    public virtual User User1 { get; set; }
    public virtual OrderStatu OrderStatu { get; set; }
    public virtual Room Room { get; set; }
}

I don't want to use fields from Order table like:

public virtual User User { get; set; }
public virtual User User1 { get; set; }

I understand that two users must be in Order, because they are both navigation properties and I just want to rename them.

And from User table like:

public virtual ICollection<Order> Orders { get; set; }
public virtual ICollection<Order> Orders1 { get; set; }

because one user must have only one list of orders (It does not matter whether he is an manager or client).

What are the best ways to solve this problems?

Svys2nov
  • 51
  • 2

0 Answers0