I have a project which has 4 DBs: Teachers, Products, Product Groups, and PGPs.

Teacher -> Product Group is a one to many relationship Product Group -> Products is a many to many relationship with PGPs in the middle.

I am able to access and display info from my Teacher, Product Group and Product DBs individualy, but am stuck when it comes to the product/product group many to many relatioship.

I have this custom route in my API:

[Route("api/productgroups/{groupId}/products")]
    public IQueryable<ProductModel> GetProductsByGroupId(int groupId)
    {
        return db.Products.Where(p => p.PGPs.Any(pgp => pgp.ProductGroupID == groupId)).ProjectTo<ProductModel>();
    }

This works well, and I can test it by typing the route in my address bar while the app is running. All data is there as I would expect it.

The hole in my knowledge comes when I try to display the data on the front end of my site. I would like to pass in a GroupID and return a table of products containing that GroupID. I've been using AngularJS dor the rest of the project.

I hope this makes a little sense.

Related posts

Recent Viewed