Map tables relationship from legacy database w/ entity framework with only primary keys

后端 未结 1 380
日久生厌
日久生厌 2021-01-23 17:15

data (table name)

dataid PK,

value1,

value2,

value3

data_address (table name)

dataaddressid PK,

相关标签:
1条回答
  • 2021-01-23 17:35

    If you are certain that the database's integrity is sound you could just map the tables and create the associations manually in the EF model.

    In a database-first mode I fiddled a bit with a simple data model: Parent + Child without FK. The tables were of course imported without association between them. Then I did "Add Association..." on the Parent, like so:

    enter image description here

    Note: no foreign key property yet. I added it manually in the properties of the association:

    enter image description here

    enter image description here

    And I could run a linq query on Parent.Children.

    I think this is the easiest way for you. The edmx design surface gives you some guidance to see which associations you created. You can always add a code generation item to generate a DbContext which is easiser to work with than the default ObjectContext.

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