question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Take advantage of ownership to enable aggregate behaviors in model

See original GitHub issue

This is a grouping of related issues. Feel free to vote (👍) for this issue to indicate that this is an area that you think we should spend time on, but consider also voting for individual issues for things you consider especially important.


This an “epic” issue for the theme of automatic aggregate behaviors in the model based on ownership. Specific pieces of work will be tracked by linked issues.

Backlog

  • A delete orphans/cascade delete policy an can be applied by convention to owned entities #10179
  • For example, we could implement client-only cascade delete for aggregates, which should be fully loaded and hence won’t have issues with some entities needing to be deleted in the store. However, also consider that an aggregate cannot have true cycles, and hence the SQL Server limitation might not be as bad. #12168
  • A cascade update could also be applied #10551)
  • Smarter logic can be applied to infer the intended state of objects while merging a detached graph into a context: non root objects within the aggregate that are no longer reachable can be marked as deleted, while non root objects that appear for the first time within the aggregate being merged can be marked as added. The same assumptions can’t be made with the same confidence across aggregate boundaries. This could be handled by a new method: ‘Merge()’ (related to #5536)
  • Concurrency control could be delegated to the aggregate root when it’s not mapped to the same store object #18529
  • Allow related entities to be passed to constructor of aggregate root #12078
  • Allow to configure an owned navigation as lazy
  • Entity Equality: owned entity support #15936
  • Decide how null owned properties are handled by SaveChanges #24581
  • Shouldn’t DbContext.Update() result in commands to delete (set all null) an entity’s owned type navigation property if it is null? #26493
  • Make EntityEntry methods (GetDatabaseValues, etc) aggregate friendly #13890
  • Fluent API - Mapping an index over more than one column across entity types. #11336
  • Allow moving the navigation and/or the FK to an owned type for a relationship that involves the principal #26505

Original issue

Define included properties

When you get an entity from the database and you also want to get a “child entity”, you need to pass that “child object” as an expression in order to also get it from the database (when not using lazy loading).

public class Parent
{
    public Child Child { get; set;}
}
public class Child
{   
}

var dataContext = new DataContext();
var parents = dataContext.Parents.Include(p => p.Child).ToList();

Would it be possible to add an new attribute that will be read by the datacontext and add the include statements automatic?

public class Parent
{
   [Include]
    public Child Child { get; set;}
}
public class Child
{   
}

var dataContext = new DataContext();
var parents = dataContext.Parents.ToList();  // Child entity is also read from the database

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:33
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
HappyNomadcommented, Nov 20, 2016

Just because an entity’s property is an aggregate part of the entity, doesn’t mean you always want to include it. But sometimes you do. Instead of [Include], consider introducing [Part] to indicate a part-whole relationship. After appropriately dispersing [Part] throughout your model, you query like this:

var parents = dataContext.Parents.IncludeParts().ToList();

This recursively loads parts and parts of parts, etc…

Also consider adding a RequiresFilter property to [Part] like this:

public class PartAttribute : Attribute
{
    public bool RequiresFilter { get; set; }
}

Setting this property to true indicates that a filter must be specified for the property as part of a query with IncludeParts, or else an exception is thrown upon loading.

4reactions
popcatalin81commented, Apr 3, 2015

@kennytordeur this is a very dangerous feature. In a large application someone would “think” they always want to load B & C together with A. However in other parts of the code this creates issues due to the fact that it creates overly complex queries (perf) or loads more than necessary (attach/detach scenarios over the wire/web services) or breaks some logic IE: someone checks if B is not loaded (== null) then loads B and B1+B2 etc (an entire graph) after this change application is broken because B is loaded but not B1+B2.

Also there are alternative solutions to this, like: A repository pattern: List<Parent> GetParents(){return datacontext.Parents.Include(p => p.Child);}

Which is also more flexible because it allows you to customize the query with more than just includes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DDD - Aggregate that changes "owner" mid-process
This is my team's first time implementing this architecture, and I'm struggling to finalize the aggregate design because the core entity changes ...
Read more >
Relocate ownership of a local tier (aggregate) within an HA pair
You can change the ownership of local tiers (aggregates) among the nodes in an HA pair without interrupting service from the local tiers....
Read more >
Problems Using Aggregate Data to Infer Individual Behavior
First, I estimate the relation between each of three key measures of investors' legal protection and ownership concentration using country averages. To make...
Read more >
Developments in Modelling Risk Aggregation
How firms use Risk Aggregation Models ('RAM's') ... The requirements do allow some diversification benefits within the categories.
Read more >
Combined third-party ownership and aggregation business ...
The combined third-party ownership–aggregation business model could drive adoption because it can enhance grid stability and reliability, and resilience at the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found