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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:25:09+00:00 2026-05-17T18:25:09+00:00

I have multiple tables that are all linked back to a central table with

  • 0

I have multiple tables that are all linked back to a central table with foreign keys. I want to be able to create a new record in table 2, but I’m having trouble because I don’t know how to create a new instance of table 2’s record while referencing the ID of the record it will be tied to.

EXAMPLE:

Database: Collection

Table: Collection
Field 1: id
Field 2: name

Table: Book
Field 1: collectionId
Field 2: id
Field 3: name

Now, I don’t want to be able to create a book without setting it’s collectionID, but I can’t figure out how this should be divided in the controllers/views.

Should Book have a controller separate from Collection, or should the Collection controller have a createBook method, separate from it’s own create method?

I want to call the createBook method (from it’s own controller, or the Collection controller) from the Collection Details view.

When I invoke the create method of Book, how do I create a new Book that is instantiated with the collectionId set from the details view of the Collection item that was listed in the details view?

I should point out, I’m using the entity framework for my model, and I’m definitely new to this.

Thanks for any help

  • 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-17T18:25:10+00:00Added an answer on May 17, 2026 at 6:25 pm

    Try not to create/separate controllers based on your entity model, create/separate them based on the UI and URL Routes.

    I’m guessing you have a View called “CreateBook”, which is (hopefully) bound to a strongly-typed “Book” entity.

    When you submit the form, you should have a controller method with [HttpPost].

    Then you can do this to submit the book:

    string bookName = Request.Form["Name"];
    int collectionId = Request.Form["CollectionID"];
    

    or pass it through as a strongly-typed model:

    public ActionResult CreateBook(Book book) { }
    

    Then you do this:

    Book newBook = new Book (book.Name, book.CollectionID);
    someDal.CreateBook(newBook);
    

    When you import your model into the EDMX, make sure you tick “Include Foreign Keys in the Model”.

    What this does is add the “CollectionID” FK to the Book entity, allowing you to bind to this and have access to this property on each book model.

    There is a really good article here on CRUD operations with Strongly Typed ASP.NET MVC Views, should put you on the right track.

    HTH.

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

Sidebar

Related Questions

I have a stored procedure that returns multiple tables. How can I execute and
A table that extends onto multiple printed pages will have its thead and tfoot
I have a table with multiple rows. Each row is a form. I want
I have multiple tables with an id component. I'd like to use LINQ to
I have an SQL database with multiple tables, and I am working on creating
I have multiple rows in a table, in one of which is a link
I have a table with columns Index, Date where an Index may have multiple
Below is my table, a User could have multiple profiles in certain languages, non-English
I have a table UserAliases ( UserId, Alias ) with multiple aliases per user.
I have a table with game scores, allowing multiple rows per account id: scores

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.