LOL. This is perhaps the most complicated case for EF to do the modeling? I even doubt if this scenario is supported. My business is like I need to know which Application matches another Application for what reason. So the table representing the relationship looks like this:
PrimaryApplicationID, SecondaryApplicationID, MatchedRuleID
OK. Now is it even possible I can use EF to represent this relationship? If yes, what special thing I need to do in database side? I'm using database-first approach, but this doesn't quite matter, does it?
Thanks for any clue.
With Database-First you would create three tables, for example:
Table Applications
ApplicationId int NOT NULL PK
...Other columns...
Table Rules
RuleId int NOT NULL PK
...Other columns...
Table MatchingApplications
PrimaryApplicationId int NOT NULL PK, FK to Applications table
SecondaryApplicationId int NOT NULL PK, FK to Applications table
MatchedRuleId int NOT NULL FK to Rules table
The double-PK in MatchingApplications
is meant to be a composite key. The double-FK is meant as two separate foreign key relationships to the same table Applications.
You cannot enable cascading delete for both relationships because SQL Server won't allow more than one cascading delete path between the same tables.
EF should create three entities from this database schema:
Application
entity with two collections with element type MatchingApplication
Rule
entity with one collection with element type MatchingApplication
MatchingApplication
entity with two navigation references of type Application
and one navigation reference of type Rule
.Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments