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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:42:02+00:00 2026-05-23T03:42:02+00:00

Say I have a one to many relationship in my database between orderstatus and

  • 0

Say I have a one to many relationship in my database between orderstatus and orders. My view for creating an new order would need to have a dropdown of orderstatuses.

I have separate repositories for order and order status as well as seperate services for manipulating orders and order statuses. Something like:

public class OrderService : IOrderService
{
    private readonly IRepository<Order> _orderRepository; 
    public OrderService(IRepository<Order> orderRepository) {_orderRepository = orderRepository }
    public IEnumerable<Orders> GetAllOrders(){...}
}

public class OrderStatusService : IOrderStatusService
{
    private readonly IRepository<OrderStatus> _OrderStatusRepository; 
    public OrderStatusService(IRepository<OrderStatus> orderStatusRepository)  {_orderStatusRepository = orderStatusRepository }
    public IEnumerable<OrderStatus> GetAllOrderStatuses(){...}
}

My order controller has a reference to the OrderService, a bit like this:

public class OrderController : Controller
{
 private readonly IOrderService orderService;

What is the best way to do get a list of orderstatuses from the db?

1) Include a reference to both repositories in the OrderService and include a method that will return orderstatuses.

public class OrderService : IOrderService
{
    private readonly IRepository<Order> _OrderRepository; 
    private readonly IRepository<OrderStatus> _OrderStatusRepository;  ...

2) Make the controller aware of both services and use the GetOrderStatus method to get the list of OrderStatuses:

  public class OrderController : Controller
{
 private readonly IOrderService orderService;
 private readonly IOrderService orderStatusService; ...

3) Use the OrderStatusService from the OrderService to get the list of Order Statuses, something like:

    public class OrderService : IOrderService
{
    private readonly IRepository<Order> _orderRepository; 
    private readonly IOrderService _orderService; ...
    public IEnumerable<OrderStatus> GetOrderStatuses()
    { return _orderService.GetOrderStatuses; } ...

4) Another cool way that I cant think of 🙂

  • 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-23T03:42:03+00:00Added an answer on May 23, 2026 at 3:42 am

    Personally, I would go with your option #1 – combine your two existing services into one. Remember your service layer is supposed to act as a facade over lower level services like your repositories. Having two separate services for this kind of defeats the purpose.

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

Sidebar

Related Questions

Let's say you have a one-to-many relationship between Users and Orders (where one user
Lets say I have a Customers table and an Orders table with a one-to-many
i have a database with 3 tables in a many-to-many relationship. one is the
Say you have a one to one relationship in your entity model. The code
Okay I have a one-to-many relationship in core data. A Meal can consists of
Say I wanted to have a project, and one-to-many with to-do items, and wanted
I understand how to design a database schema that has simple one-to-many relationships between
Let's say I have two tables employee and salary with a 1:N relationship (one
Say I have one superclass, and several subclasses inheriting it. I'd like to cram
Lets say I have one table called REVIEWS This table has Reviews that customers

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.