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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:21:02+00:00 2026-05-29T19:21:02+00:00

This will create two tables Ingredient and Recipe and an additional table for many-to-many

  • 0

This will create two tables “Ingredient” and “Recipe” and an additional table for many-to-many mapping.

public class DC : DbContext {
    public DbSet<Ingredient> Ingredients { get; set; }
    public DbSet<Recipe> Recipes { get; set; }
}

public class Ingredient {
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Recipe> Recipes { get; set; }
}

public class Recipe {
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Ingredient> Ingredients { get; set; }
}

Question: I want to include additional column “quantity” in the third mapping table that will be created by Entity Framework. How to make that possible? Thanks in advance.

  • 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-29T19:21:04+00:00Added an answer on May 29, 2026 at 7:21 pm

    When you’ve got some extra information, I suspect it won’t really count as a mapping table any more – it’s not just a many-to-many mapping. I think you should just model it as another table:

    public class Ingredient {
        public int Id { get; set; }
        public string Name { get; set; }
        public virtual ICollection<RecipePart> RecipeParts { get; set; }
    }
    
    public class RecipePart {
        public int Id { get; set; }
        public Ingredient { get; set; }
        public Recipe { get; set; }
        // You'll want to think what unit this is meant to be in... another field?
        public decimal Quantity { get; set; }
    }
    
    public class Recipe {
        public int Id { get; set; }
        public string Name { get; set; }
        public virtual ICollection<RecipePart> Parts { get; set; }
    }
    

    So now you don’t really have a many-to-many mapping – you have two ordinary many-to-one mappings. Do you definitely need to “ingredient to recipes” mapping exposed in your model at all? If you want to find out all the recipes which use a particular ingredient, you could always do a query such as:

    var recipies = DB.Recipies.Where(r => r.Parts
                                           .Any(p => p.Ingredient == ingredient));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: CREATE TABLE Table1 ( ID VARCHAR(15), Value INT ); INSERT
I have two tables, categories and products. I am using CodeIgniter. Categories CREATE TABLE
I have these two tables: CREATE TABLE x ( id INT NOT NULL, exclude
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
I have two tables detail and head. The detail table will be written first.
i want to create a join between two tables and that the result will
I have two tables: CREATE TABLE Event_details( event_no INTEGER AUTOINCREMENT NOT NULL, no_players INTEGER
I have the following two tables: CREATE TABLE Test_Main ( [ID] INT IDENTITY ,
This is in SQL Server 2008. I plan to create two tables to represent
I have two tables: CREATE TABLE `category` ( `category_id` int(10) unsigned NOT NULL AUTO_INCREMENT,

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.