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

  • Home
  • SEARCH
  • 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 294575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:22:46+00:00 2026-05-12T06:22:46+00:00

I am new to the MVC/Linq party (coming from Java). I know that I

  • 0

I am new to the MVC/Linq party (coming from Java).

I know that I can use something like the following to get strongly typed access, but what about if I want to use a join in my linq query?

public void IQueryable<Product> GetItems(int CategoryID)

{
…linq query…
}enter code here

  • 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-12T06:22:46+00:00Added an answer on May 12, 2026 at 6:22 am

    In your example, if you have used the designer to create your Linq to SQL data context, and there is a foreign key relationship between the Product and Category tables in your database, then the Category will be a property in your Product class, so there is no need to join them.

    Something along the lines of the following should help (guessing property names; db is your data context):

    public IQueryable<Product> GetItems(int categoryID)
    {
      return db.Products.Where(p => p.Category.CategoryID == categoryID).AsQueryable();
    }
    

    Or if you are not comfortable with the lambda syntax, then the following is synonymous:

    public IQueryable<Product> GetItems(int categoryID)
    {
      var result = from p in db.Products
          where p.Category.CategoryID == categoryId
          select p;
      return result.AsQueryable();
    }
    

    The Product class has a Category property, providing strongly typed access to all of the properties in category. You would use something like product.Category.Name to get the category name for example.

    Also, there are a plethora of good Linq to SQL tutorials out there. Try the following:

    http://it-box.blogturk.net/2007/10/19/linq-to-sql-tutorial-series-by-scott-guthrie-pdf-book-format/

    http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx

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

Sidebar

Related Questions

I am new MVC 3.0 Razor. I am using LINQ to get the details
I am quite new with Linq to SQL and MVC but I follow the
I have started a new mvc project and clicked on project\properties\web - use local
Pretty new to MVC and the like. I have a class the looks like
Still extremely new to the whole MVC/LINQ thing. I'm in the processes off building
I am new to linq and asp.net mvc and right now i am developing
Ok the thing is that I am using asp.net mvc with linq to sql.
I am new to MVC and LINQ. I have a table with three columns
newbie writing, I'm new to MVC 2 C# and using EntityFramework with LINQ. In
I'm an experienced programmer, but new to LINQ/Moq/Ninject/MVC/MS Test/etc and have run into an

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.