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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:24:34+00:00 2026-05-20T02:24:34+00:00

About Domain Driven Design, Order and OrderLines are always seen as an aggregate, where

  • 0

About Domain Driven Design, Order and OrderLines are always seen as an aggregate, where Order is the root. Normally, once an order is created, one cannot change it. In my case however, that is possible. Instead each order has a state determining whether the order can be changed or not.

In this case, are both Order and OrderLines their own “aggregate root”? I need to be able to update order lines, so I figure that they should have their own repository. But I do not want to retrieve order lines, and persist them without the order. So this indicates that there’s still an aggregate where Order is the root with a factory method to create order lines (Order.CreateOrderLine(quantity, text, …).

Another approach could be to update the Order when the order lines collection has been modified, and then call UpdateOrder(Order). I would need some way of detecting that only the collection should be updated, and no the Order itself (using Entity Framework).
What do you think?

  • 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-20T02:24:35+00:00Added an answer on May 20, 2026 at 2:24 am

    Order lines shouldn’t be an aggregate of it’s own, and doesn’t need it’s own repository. Your aggregate should be setup something like this…

    public class Order
    {
        private List<OrderLine> _orderLines;
        private OrderState _orderState;
    
        public IEnumerable<OrderLine> OrderLines 
        {
            get { return _orderLines.AsReadOnly();}
        }
    
        public OrderState Status
        {
            get { return _orderState; }
        }
    
        public void DeleteOrderLine(Guid orderLineID)
        {
            if (Status.IsProcessed)
                throw new InvalidOperationException("You cannot delete items from a processed order");
    
            OrderLine lineToRemove = _orderLines.Find(ol => ol.Id == orderLineID);
    
            _orderLines.Remove(lineToRemove);
        }
    
        public void AddOrderLine(Product product, int quantity)
        {
            if (Status.IsProcessed)
                throw new InvalidOperationException("You cannot add items to a processed order");
    
            OrderLine line = new OrderLine(product.ProductID, (product.Price * quantity), quantity);
    
            _orderLines.Add(line);
        }
    }
    

    Entity framework has some built in features to detect changes to your object. This is explained here (conveniently with an order/order lines example): http://msdn.microsoft.com/en-us/library/dd456854.aspx

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

Sidebar

Related Questions

I read that Domain Driven Design is about concentrating on the problem domain instead
I'm hearing more and more about domain specific languages being thrown about and how
About a year ago, I picked up Scott Ambler's Refactoring Databases: Evolutionary Database Design
This question is about App domains and Sessions. Is it possible to have IIS
I'm playing about with lighttpd on a small virtual private server. I two domains
About 6 months ago I rolled out a site where every request needed to
About 2 years ago I dropped windows from my home PC and switched 100%
About a half dozen times now, I’ve been doing a regular chore in Visual
Thinking about getting into .net technology project management I've had plenty of experience with
Thinking about a Windows-hosted build process that will periodically drop files to disk to

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.