0

I am trying to filter based on a table hierarchical relationship. But getting the error below.

I am trying to filter based on the variable C in c.Departments_Category_Registration.Category_Name == C

Can anyone advise, here is my code

var model = from r in _context.Departments_SubCategory_Registration.Include(c => c.Departments_Category_Registration.Category_Name == C)
                where r.IsEnabled == true

                select r;
    return View(model);

and error message
InvalidOperationException: Incorrect include argument: c => (c.Departments_Category_Registration.Category_Name == __C_0)

update. I changed my code to this below and get no error, but yields no results

      [Route("/{C}")]
    public async Task<IActionResult> Product(String C)
    {

        return View(await _context.Departments_SubCategory_Registration.Include(c => c.Departments_Category_Registration)


        .Where (d => d.IsEnabled == true)

                     .Where(r => r.Departments_Category_Registration.Category_Name == C).ToListAsync());
3
  • updated my code above Commented Jul 9, 2019 at 22:05
  • I tried you code and it works well.Make sure that your database has the record whose IsEnabled is true and its Departments_Category_Registration.Category_Name is C.Could you share your models to us? Commented Jul 10, 2019 at 6:15
  • hi guys, thanks for your contribution. I found the problem was that, though I had added FK to my model, I had not added the correct key name in the Departments_SubCategory_Registration model, unfortunately it did not give an error at runtime. Its working now, many thanks Commented Jul 10, 2019 at 11:20

1 Answer 1

1

You pass condition to the Include method. It's supposed to accept the property only. Change it to .Include(c => c.Departments_Category_Registration) and move the match by name condition under Where clause.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.