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

The Archive Base Latest Questions

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

I have 2 tables: Categories (int Id, string Title) Works (int categoryId, string WorkTitle,

  • 0

I have 2 tables:

  1. Categories (int Id, string Title)
  2. Works (int categoryId, string WorkTitle, int id)

Table Works has a foreign key (many to single) to Categories table.

I want to have such result:

    Title (id 1)

    WorkTitle (Works.id) | WorkTitle (Works.id) | WorkTitle (Works.id) (this is works in thsi category)


    Title (id 2)

    WorkTitle (Works.id) | WorkTitle (Works.id) | WorkTitle (Works.id) (this is works in thsi category)

......

    Title (id n)

    WorkTitle (Works.id) | WorkTitle (Works.id) | WorkTitle (Works.id)(this is works in thsi category)

What should be Model, View And Controller for do this?

Thanks a lot!

  • 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-22T23:53:12+00:00Added an answer on May 22, 2026 at 11:53 pm

    This should get you started. I’m assuming Entity Framework 4.1 code first. Use the ADO.NET Poco Entity template from NuGet to fill in the database initialization stuff.

    Model

    public class Category
    {
        public virtual int Id { get; set; }
        public virtual string Title { get; set; }
        public virtual ICollection<Work> Works { get; set; }   
    }
    
    public class Work
    {
        public virtual int Id { get; set; }
        public virtual string Title { get; set; }
    }
    

    Controller

    public ActionResult Details(int id)
    {
        Category c = context.Categories.Single(x=>x.Id == id);
        return View(c);   
    }
    

    View

    @model ICollection<Category>
    @{
        foreach(Category c in Model)
        {
            <h1>@c.Title</h1> (id @c.Id)
            <ul>
            foreach(Work w in c.Works)
            {
               <li>@w.Title (@w.Id)</li>
            }   
            </ul>
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables in my DB (MySQL). categories (name:string) items (name:string, category_id:int) votes
I have the following tables: Cateogories CategoryID (int) Primary Key CategoryName (varchar) Items ItemID
I have three tables: categories, languages and categories_languages. Categories_languages is many to many table
I have the following tables: 1-Categories: -CategoryID -CategoryName -ParentID 2-Items: -ItemId -ItemName -CategoryID categories
I have 3 tables (scenes, categories, scenes_categories ) in a many to many relationship.
I have two tables, categories and products. I am using CodeIgniter. Categories CREATE TABLE
I have the following mysql tables: CREATE TABLE `video` ( `video_id` int(11) unsigned NOT
I have a table:'Categories' which has two fields:Category_ID and Category. Data in Category_ID field
I have two tables as follows: Table user_prefs: user_prefs_id int(11) PK user_id int(11) item
I have 2 MySQL tables: categories (id int, name varchar(1000)) And products (id int,

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.