How to map a child item when creating a parent item? (not a bug more a question)
See original GitHub issueIs it even possible like this?
TestDbContext db = await TestDbContext.CreateAsync();
Role role = new Role() { Name = "Test" };
db.Roles.Add(role);
await db.SaveChangesAsync();
// Create user and assign existing role
User user = new() { Name = "Example" };
user.Roles.Add(role);
await db.MapAsync<User>(user);
await db.SaveChangesAsync();
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Can you parent a bug under an epic? - azure devops
Use the mapping pane in the backlog to map a bug to an epic (this also is only designed to allow you to...
Read more >CSV import Parent-child mapping | Jira
Firstly, make sure the exported CSV file contains at least the following columns for the parent-child mapping: Issue type, Issue key, ...
Read more >Resolve nest, display, and reorder issues for work items
You can quickly map product backlog items to features, which creates parent-child links in the background. Don't create a hierarchy of backlog ...
Read more >Link work items and other objects - Azure Boards
To quickly link backlog items to portfolio backlog items with parent-child links, use the mapping pane to organize your backlog. · To create...
Read more >All about subitems
To convert a subitem to an item on your board, select a subitem from the left side and click "Convert" on the bottom...
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 Free
Top 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
So, the mapper works with two concepts, the DTO and the Entity which may be the same type, or not.
For example:
Mapper then will:
[Aggregation] are supossed to be independent entities/graphs that the entity is referring to. And shouldn’t be added/deleted along with it. e.g.: Invoice -> InvoiceType That’s why only Id is mapped for aggregations and is marked as Unmodified. If the aggregated entity doesn’t exists, an fk error is thrown when saving.
[Composition] are entities that form part of the same concept and should be updated/deleted with the root entity. e.g.: Invoice -> InvoiceDetail.
Another interesting thing. Given the previous DTO and Entity definitions, values are always copied, even when they are the same type. The User that you passed to the MapAsync method is not the same that gets attached to the context. The attached one comes from the initial query or is instantiated by the mapper, and it’s returned by the MapAsync method.
var attachedUser = await db.MapAsync<User>(detachedUser);
In this example, attached and detached users are not the same instance.In this your case, MapAsync will:
This is a very high level description, as there much more, like circle dependencies (BackReference in the code), type configuration, mapping configuration, the dynamic code, etc.
Feel free to ask on a certain topic if you are interested on it.
Ah the return value, thanks for pointing that out! With that I can work something out. Many thanks again.