Linq To SQL Without Explicit Foreign Key Relationships

前端 未结 7 1515
陌清茗
陌清茗 2020-12-16 14:54

I am working with a few legacy tables that have relationships, but those relationships haven\'t been explicitly set as primary/foreign keys. I created a .dbml file using \"

相关标签:
7条回答
  • 2020-12-16 15:48

    Go back to the designer and check the relation is set up correctly. Here is one real life example, with BillStateMasters have "CustomerMasters1" property (customers for the state):

    Ps. naming is being cleaned up ...

    Update 1: You also need to make sure both tables have a primary defined. If the primary key isn't defined on the database (and can't be defined for whatever reason), make sure to define them in the designer. Open the column's properties, and set it as primary key. That said, entity tracking also won't work if you haven't a primary key for the entity, which for deletes means it silently doesn't updates the entity. So, make sure to review all entities and to have them all with a primary key (as I said, if it can't be on the db, then on the designer).

    0 讨论(0)
提交回复
热议问题