Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im using DDD in my project and I have an entity which belong to two bounded contexts with different properties each one. Both bounded contexts add records by this entity.
How can I configure these two classes to map to same table by fluent Api?

What I have tried:

I have try that solution

entity framework core - EFCore Map 2 entities to same table - Stack Overflow[^]

but its working only if add a new record from the first bounded context. When Im trying to add from the second Im getting this error:
The value 'Id' of is unknown when attempting to save changes. This is because the property is also part of a foreign key for which the principal entity in the relationship is not known.
Posted
Updated 10-Jul-21 1:46am
v2
Comments
Manos Kanellopoulos 7-Jul-21 12:37pm    
Any idea plz?
[no name] 7-Jul-21 15:57pm    
[Table("TheTable")]
Manos Kanellopoulos 7-Jul-21 16:03pm    
Hi Gerry! If I set two classes to same table will thrown an exception it says that already a class mapping to the table
Manos Kanellopoulos 7-Jul-21 16:04pm    
Its needs something to understand that those classes are mapping to the same table
[no name] 8-Jul-21 12:45pm    
https://entityframeworkcore.com/knowledge-base/49986756/efcore-map-2-entities-to-same-table

https://stackoverflow.com/questions/49986756/efcore-map-2-entities-to-same-table

1 solution

Try using the mapped entity as a base class for two derived entities.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900