'Can EF Core map a property to a non-id column from another table?
Table1:
int Id
string Name
Table2:
int Id
string X
Is it possible to have an entity like this?
class MyEntity {
int Id { get; } // Table1's
string Name { get; }
string X { get; }
}
I do NOT want to have a separate entity for Table2.
Explanation:
The reason why I don't want a separate entity is because I'm trying to achieve encapsulation.
The Table1.Name and Table2.X go hand in hand from a business rule point of view, the properties need to be kept in "sync". One one is updated, so is the other one, based on some value logic.
With a separate entity class (Table2), it would require having the Table2.X property public so that it can be set from MyEntity entity class. Instead, I would like to have the X property in the MyEntity class, in order to set both the Name and X properties together and keep them in sync.
I think MyEntity is an aggregate.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
