How do I override the default Id field for a table in ANZ? I have created a master/detail situation with Purchase Orders and the detail table needs to be a composite key.
The scenario:
PurchaseOrder.Id is the the primary key of the parent master table. The child table, PurchaseOrderDetail should be a composite of PurchaseOrderDetail.PurchaseOrderId + PurchaseOrderDetail.LineNbr. I have been unable to determine how best to override the framework to make ANZ allow me to remove the default Id incremental created field and instead use the defined PurchaseOrderDetail.PurchaseOrderId field as the key in this entity/Dto.
Thanks,
Matt
8 Answer(s)
-
0
This is not recommended. (If you don't inherit Entity, you will lose many of the features of the framework)
-
0
This is a vauge response. What will be lost? How would you recommend maintaining the appropriate parent child relationship as the CreateOrEdit methods all need updating because Id in the child is not the parent. If I was doing database first wouldn't I have the same issue? I thought the framework supported these situations.
-
1
See https://support.aspnetzero.com/QA/Questions/3232
Abp built-in repository pattern supprts only
Id
as primary key. if you want to have composite primary keys, you can do it without going through abp repository interface (however you do lose some advantages from not using abp repository) -
0
So maybe I'm thinking about this incorrectly. How would I preform a one to many relationship with ANZ with only a single primary key?
-
0
You can
- follow Ef/Ef Core naming convention for entity properties
- decorate your entity properties with EF/EF Core Attributes
e.g. https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.ZeroCore/Authorization/Roles/AbpRole.cs#L39
see also https://docs.microsoft.com/en-us/ef/core/modeling/relationships
-
0
@ryancyq - thank you for the information and patience. This is my first real experience with EF and code-first and its got a learning curve. I was looking at the Microsoft document today and I was wondering why the RAD tool doesnt add ICollections to the foreign keys but I made the assumption it only knows a relationship exists through the foreign key not to create a collection.
Should I be adding ICollections to my master/parent tables?
-
0
@mdframe, yes you can do that. a
PurchaseOrder
most likely to have a collection ofPurchaseOrderLineItem
. -
0
@ryancyq - Thank you for all the information, I really appreciate the help!