Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:35:29+00:00 2026-05-16T20:35:29+00:00

Here is the expression x => x.stf_Category.CategoryID == categoryId x refers to an Product

  • 0

Here is the expression

x => x.stf_Category.CategoryID == categoryId

x refers to an Product Entity that contains a Category. I am trying to load all Products that match given categoryId.

In the db the Product table contains a Foreign Key reference to Category (via CategoryId).

Question: I think I am doing it wrong. Is there something else one has to do in EF4 to create a LINQ expression of this type?

Are there any good examples of EF4 Linq expressions out there? Specifically something that queries on the basis of related entities such as my problem ?

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:35:30+00:00Added an answer on May 16, 2026 at 8:35 pm

    You’re looking for the Include method.

    var query = db.Products.Include("Categories");
    

    This is commonly referred to as eager loading.

    Entity Framework will ‘infer’ the JOIN constraint based on the mapping you have specified.

    The “magic string” needs to match the Entity Set name on your EDMX.

    Check out this post for more info.

    EDIT

    I’m a little confused as to whether you want the Products and Categories, or just the Products which have a specific Category ID.

    If the latter, this is the way to go:

    var query = from p in db.products
                join c in db.categories
                on p.CategoryId equals c.CategoryId
                where c.CategoryId == someCategoryId
                select p;
    

    Keep in mind though, the above query is exactly the same result as your original query.

    If p is a product, then p.Categories will look at the Navigational Property of your Product entity on the EDMX, in which case it will be your Category FK.

    As long as you setup your Navigational properties right, p.Categories is fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a simplified version of what I'm trying to do through an expression.
I have the following regular expression with which I match a few lines. Here
I'm trying to match a URL in a string, using regex from here: Regular
I have written this regular expression here: \{t\s+i=['|]([\w\s*]+)['|]} and it matches anything that is
Here's my regular expression that I have for this. I'm in Ruby, which —
I have a program here that will solve an expression... First I need to
I need a regular expression that matches currency values similar to here: Regex for
Here's the regular expression I use, and I parse it using CAtlRegExp of MFC
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here is a regular expression I created to use in JavaScript: var reg_num =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.