- ABP Framework version: v5.0.0
- UI type: Angular
- DB provider: EF Core
Hi,
I've noticed some issue while adding child entities. Entity:
By default AbpDbContext sets ID for added entity and it works properly when you add one child and call Update on repository, but when you add two children and call Update on repo then exception is throwed (as on the picture) Is it a framework issue? or maybe my implementation is wrong?
What is the workaround? Generating IDs by my own?
Regards
5 Answer(s)
-
0
Hi,
Will this problem occur if you use EF Core directly?
-
0
Hi,
what do you mean by "EF Core directly"? Without using abp repository, without using AbpDbContext? If you want me to check whether it works without using AbpDbContext then it makes no sense for me because I want to use abp.io built in feature to automatically generate IDs for atttached (to DBContext) subentities. In my opiniony this feature does not work correctly. What is your opinion?
-
0
Hi,
I will check it.
-
0
Hi
I reproduced the problem.
You are right, ABP will automatically generate Id after entity tracking but EF Core checks for duplicate Ids and throws an exception when tracking entities.
I will try to find a way to solve the problem, for now, you need to generate ids for Children.
-
0
hi
It seems you need to set the id of your entity.
Always set GUID Ids as best practice.
See https://github.com/abpframework/abp/blob/dev/docs/en/Entities.md#entities-with-guid-keys
TrySetGuidId
This method doesn't seem to be compatible with EF Core's tracking functionality, I'll keep checking.