Take advantage of ownership to enable aggregate behaviors in model
See original GitHub issueThis 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:
- Created 8 years ago
- Reactions:33
- Comments:20 (14 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:This recursively loads parts and parts of parts, etcâŚ
Also consider adding a
RequiresFilter
property to[Part]
like this: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.@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.