When working with one-to-one relationship at the database level, we (I?) Often implement it In fact, one-to-many relationship ends.
For example:
Make Table Master (MasterID INT Primary Key)
and
< Code> Create table child (childId INT Primary key, MasterID INT, contract child_master_fk foreign key (Master ID) reference master (MasterID))
Single child
only Can refer to a guru
, there is nothing in preventing the same children
s from referring to master
, resulting in one-to- many Iste.
When creating an entity data model from such a database set up, it is reflected with the fact that the master unit will have reference to the child unit, but a master in the child's unit The unit will be a collection.
Since I look at logical relations, I hip as one-by-one, I do not expect that the child's master collection contains more than one element; Thus, I want to keep a child organization a master reference rather than a collection.
What is the correct way to accomplish this? Creating foreign key constraints in two ways at the database level? Missed the generated model?
tweak model Add a single reference property, which gives a single example and ignores the store property Then set the sole property overlooked by EF in its mapping configuration.
It is not what I call beautiful, but when using e-mail, such sacrifice is often the database already present.
No comments:
Post a Comment