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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:05:52+00:00 2026-06-14T18:05:52+00:00

I am working on asp.net mvc 4 web api with EF code first model.

  • 0

I am working on asp.net mvc 4 web api with EF code first model. I have a class with navigation property like like,

public class Branch
{
[Key]
public int Id{get; set;}
public List<book> books{get; set;}
}

and my book class is like,

public class book
{
[Key]
public int id{get; set;}
public string Name{get; set;}
}

Now i need to get list of branches so i write like,

public IQuerable<branch> GetBranches(int branchid)
{
  return context.school.where(m=>m.id==branchid).ToList().AsQuerable();
}

now i want to assign some data to book property in branch class so did like,

context.school.ToList().ForEach(m=>m.books=GetBooks(branchid));

and now to get branch i have url like,

/api/branch/12

and is there any way to get particular book in a particular branch using url like

/api/branch/12/book/567

to return book number 567 in branch number 12. please guide me.

  • 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-14T18:05:53+00:00Added an answer on June 14, 2026 at 6:05 pm

    You can use this kind of url to pass book to BranchController:

    /api/branch/12?book=567
    

    Or you can create new route for your url

    config.Routes.MapHttpRoute(
        name: "BranchBooksApi",
        routeTemplate: "api/branch/{id}/book/{bookId}",
        defaults: new { controller = "Branch" });
    

    Both options will invoke method like

    public book Get(int id, int bookId)
    {
        //...
    }
    

    Also if you need to get book (it’s not clear to me what you want – branch with single book, or just book from branch), then maybe BooksController is more appropriate place for this code.

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

Sidebar

Related Questions

I have a ASP.NET MVC 4 application with Web API. It's working great. But
I'm working my way through some ASP.NET MVC reading and I have a web
Here's the situation. What I am working with: - ASP.NET MVC 4 Web API
I am working on asp.net mvc webapi with EF code first with existing database.
I am working with the HttpSelfHostServer with asp net mvc 4 web api When
I have a working ASP.NET MVC web application to manage projects and customers. Now
I am working on an asp.net MVC 3 web application, i have the following
I am working on an asp.net mvc 3 web application , and i have
I'm currently working on an Asp.net MVC Web application. In my solution, there're two
I am working on a sql server 2008 DB and asp.net mvc web E-commerce

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.