0

I have an example of a query like the following. I have two tables named product and category. But I want him to do the search by name, not by id.I did the join but I get the error like below.The part where I get the error "from p in context.Products".The error I received is Could not find an implementation of the query pattern for source type. 'Join' not found.

public List<Product> GetProductsByCategory(int categoryId)
    {
        using (var context= new NorthwindContext())
        {
            var query= from p in context.Products
                        join c in context.Categories on p.CategoryId equals c.CategoryId
                        select new
                        {
                            ProductName= p.ProductName,
                            QuantityPerUnits = p.QuantityPerUnit,
                            UnitPrice = p.UnitPrice,
                            UnitInStock = p.UnitsInStock,
                            Category = c.CategoryName
                        };

            return query.ToList();
        }            
    }

What is the reason for this error? How can I fix.

  • Why do you think this is getting products by category? You haven't filtered your data by the categoryId that was passed in. – mason Dec 12 '19 at 18:55
  • Because I have two tables and I need to join them and list them by category name. – Nasuf Mutlu Dec 12 '19 at 19:02
  • You completely missed my point. You have a method called `GetProductsByCategory` that accepts a parameter called `categoryId` that you are doing nothing with. You need to filter the results returned by the parameter that was passed in. If you want to filter by category name, then you'd need to filter by that. Simply doing a join is not the same thing. – mason Dec 12 '19 at 19:09
  • 3
    Does this answer your question? [Could not find an implementation of the query pattern](https://stackoverflow.com/questions/8215773/could-not-find-an-implementation-of-the-query-pattern) – devNull Dec 12 '19 at 19:09
  • not exactly.Sent parameter "List GetProductsByCategory (int categoryId);"class going into the form.It needs to come with the name of the category id, not the query with linq in it.I'm trying to top the architecture on the page. How can I do this or find an instance – Nasuf Mutlu Dec 12 '19 at 19:12

1 Answers1

0

Try adding using statement for linq:

using System.Linq;
jasonmchoe
  • 491
  • 2
  • 6
  • Ohh thanks. I finished it. Now "return query.ToList ();" I get errors in.I'm working on layered architecture. – Nasuf Mutlu Dec 12 '19 at 18:59
  • What is the error? In the code above, "query" is undefined. Maybe you are looking for sorgu.ToList() – jasonmchoe Dec 12 '19 at 19:01
  • dgwProduct.DataSource = _productService.GetProductsByCategory(Convert.ToInt32(cbxCategory.SelectedValue)); I want to search for data with combobox in the form."cbxCategory.SelectedValue" I send a parameter in the form of. – Nasuf Mutlu Dec 12 '19 at 19:06
  • Sent parameter "List GetProductsByCategory (int categoryId);"class going into the form.It needs to come with the name of the category id, not the query with linq in it – Nasuf Mutlu Dec 12 '19 at 19:07
  • That sounds like another question ... post another question with the code and the error. – jasonmchoe Dec 12 '19 at 19:08