Error with Entity Framework Associations Because the attributes of the Dependent Role are not the most important ones.

c# dns domain-driven-design entity entity-framework


By use of Entity Framework 4.1

The following tables are the ones I use using Entity Framework.

  • User ( UserId PK identity, UserName, Password )

  • Physician ( PhysicianId unique identity, UserId refereces User PK, PhysicianName )

  • PhysicianSite ( SiteId, Location, PhysicianId FK to Physician table)

Problem. Because PhysicianId is not the primary key on the Physician table, Entity Framework will not let me associate Physician with PhysicianSite.

Because my program contains several categories of Users, such Patients, User is the foundation of the Physician.

The next problem message appears.

Multiplicity is not valid in the role of "Physician" in the connection of "PhysicianSitePhysician," according to Error 2 Error 113. The upper limit of the Dependent Role's multiplicity must be * since the Dependent Role's qualities are not its defining characteristics.

Could someone please explain how I may link Physician to PhysicianSite inside Entity Framework without PhysicianId serving as the table's primary key?

12/9/2011 7:37:32 PM

Accepted Answer

Foreign keys must connect to a table's main key for Entity Framework to perform properly. Entity Framework's main key does not, however, have to correspond to the database's primary key. The PhysicianId will not be verified as the main key if you tell EF that it is. And the PhysicianId will gladly accept foreign keys.

You're out of luck if some of your foreign keys point to PhysicianId and others to the actual main key, but it doesn't seem like you do.

12/9/2011 7:52:59 PM

Popular Answer

Remove any columns in your link tables that contain identity specifications (it would restrict the link table to only one copy of the ID for that linked table).

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow