title: How to filter data in ASP.NET Web MVC App
body: <p>I am working on a school project, I need to solve how to present PRODUCTS data, by selecting the CUSTOMER name and Order. I already have prepared models and I inserted them into my app. For example, if it is required to filter the product based on category and customer, this would not be a problem, because these three tables are simply linked by adding a foreign key CATEGORY AND CUSTOMER to the PRODUCT table. Using this code:</p>
  <pre><code>var categories = _context.Categories;
              Category category = new Category();
              category.CategoryName = &quot;Reset&quot;;
              category.CategoryId = -1;
              categories.Add(category);
              ViewData[&quot;CategoryId&quot;] = new SelectList(categories, &quot;CategoryId&quot;, &quot;CategoryName&quot;,CategoryId);
              ViewData[&quot;SupplierId&quot;] = new SelectList(_context.Suppliers, &quot;SupplierId&quot;, &quot;CompanyName&quot;,SupplierId);
              if(SupplierId!=null &amp;&amp; CategoryId != null &amp;&amp; SupplierId != -1 &amp;&amp; CategoryId != -1)
              {
            var northwind21Context1 = _context.Products.Include(p =&gt; p.Supplier).Include(p =&gt; p.Category)
                      .Where(p=&gt;p.CategoryId==CategoryId &amp;&amp; p.SupplierId==SupplierId)
                      .Select(p=&gt;p);
                  return View(await northwind21Context1.ToListAsync());
              }
              var northwind21Context = _context.Products.Include(p =&gt; p.Category).Include(p =&gt; p.Supplier);
              return View(await northwind21Context.ToListAsync());
  </code></pre>
  <p>But, if i want , instead (p =&gt; p.Supplier).Include(p =&gt; p.Category), code this, (p =&gt; p.Customer).Include(p =&gt; p.Orded),  I won't be able to do that, beceause class products doesnt have CustomerID, and and that class has this connection to orders :
  public virtual ICollection OrderDetails { get; set; } Class OrderDetails has OrderID(probably foreign key of ORDER class, and Class Customer has this connection to the orders: public virtual ICollection Orders { get; set; }</p>
  <p>So, this is 4 relationship tables, Product, Order, OrderDetails, and Customer. I will attach 4 pictures for every class.
  Please help me with how to write a code to filter this data.<a href="https://i.stack.imgur.com/QWKVM.png" rel="nofollow noreferrer">ORDER</a>
  <a href="https://i.stack.imgur.com/e29jO.png" rel="nofollow noreferrer">CUSTOMER</a>  <a href="https://i.stack.imgur.com/eiACl.png" rel="nofollow noreferrer">ORDEDDETAIL</a>  <a href="https://i.stack.imgur.com/n9NLD.png" rel="nofollow noreferrer">PRODUCT</a></p>