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 8017703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:55:18+00:00 2026-06-04T20:55:18+00:00

On SQL I have 3 tables: Organization(id, name) , Category(id, name) , Catalog(org_id, cat_id)

  • 0

On SQL I have 3 tables: Organization(id, name), Category(id, name), Catalog(org_id, cat_id) – mapping table between Organizations and Categories.
ADO.NET DbContext Generator created for me 2 classes:

public partial class Organization
{
    public Organization()
    {            
        this.Category = new HashSet<Category>();
    }

    public int id { get; set; }
    public string name { get; set; }       

    public virtual ICollection<Category> Category { get; set; }
}

public partial class Category
{
    public Category()
    {
        this.Organization = new HashSet<Organization>();
    }

    public int id { get; set; }
    public string name { get; set; }       

    public virtual ICollection<Organization> Organization { get; set; }
}

How can I select all organizations that mapped to cat_id = 1 using LINQ?
Like I do it using t-sql:

SELECT * 
FROM Organization o
INNER JOIN Catalog ct ON o.id = ct.org_id
INNER JOIN Category cg ON ct.cat_id = cg.id
WHERE cg.id = 1

I tried

var model = _db.Category
            .Where(c => c.id == 1)
            .Select(c => c.Organization);

But I have troubles with type defined in view like

@model IEnumerable<Project1.Models.Organization>
  • 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-06-04T20:55:20+00:00Added an answer on June 4, 2026 at 8:55 pm

    From your code there I can only presume that you’re not creating an Enumerable from the query. Your code:

    var model = _db.Category.Where(c => c.id == 1).Select(c => c.Organization);
    

    Is not an enumerable as your model is defined. Try:

    var model = _db.Category.Single(c => c.id == 1).Organizations.ToList();
    

    Which will convert the query into an enumeration of the results, which would then satisfy the requirements of your model.

    EDIT
    On second looks, it appears that your model is not a 1:M relationship, which could be the issue you’re having.

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

Sidebar

Related Questions

i have four tables like below in sql server 2008 : TABLE 1 ->
In SQL Server 2008 I have two tables. One table for users: id_user -
I have a organization name table with the following structure given below: CREATE TABLE
I have the following tables in my database: Employee Table which consists of Name,
We have two tables in a SQL Server 2005 database, A and B.There is
I have 3 sql tables: In first I store products with key PID. In
I have an SQL database with a set of tables that have Unique Id's.
I have SQL Server 2008 Ent and OLTP database with two big tables. How
I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile
In SQL Server 2008: I have two tables, dtlScheme and dtlRenewal, with a one

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.