I have a working complaint controller that has a model with many tables. One of the tables called Association and has a relationship to the customers table with the primary key from the customers table, "Cust_ID". There can be many associations for multiple points of contact.

I can already return and include all the related tables to the orders but I am having a hard time understanding how to return all the customers to this related complaint:

My Repository to getAllOrderslook like this:

 public IEnumerable<COMP> getAllOrders()
    {
        try
        {
            return _context.Orders

                .Include(t => t.ASSOCs)
                .ToList();
        }
        catch (Exception ex)
        {
            _logger.LogError("Could not get complaint with checklist", ex);
            return null;
        }
    }

My Assocs model looks like this:

public class ASSOCs
{
    [Key]
    public int AIO_ID { get; set; }

    public Nullable<int> COMP_ID { get; set; }
    public Nullable<int> Cust_ID{ get; set; }
    public string LINK_TYPE { get; set; }

    public virtual ICollection<ALLEGATIONS> ALLEGATIONs { get; set; }

    public virtual CUSTOMER CUSTOMERs{ get; set; }
    public virtual ORDER Orders{ get; set; }
}

And my Customer model looks like this:

public class CUSTOMER
{
    [Key]
    public int Cust_ID{ get; set; }

    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
    public string Department { get; set; }

    public ICollection<ASSOC_INC_OFF> AssocEntries { get; set; }
}

Question Is my model right for the customer model to bind the the ASSOCs table together and how do I include the Customer information in my repository in reference to an order?

Related posts

Recent Viewed