Map tables relationship from legacy database w/ en

2019-03-01 07:38发布

data (table name)

dataid PK,

value1,

value2,

value3

data_address (table name)

dataaddressid PK,

dataid - id to errenddataid,

addressid1 - id to en addressid,

addressid2 - id to en addressid,

type

address (table namne)

addressid PK - id to addressid1 or addressid2,

address1,

address2,

name,

zipcode,

city

I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that!

1条回答
▲ chillily
2楼-- · 2019-03-01 08:02

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.

查看更多
登录 后发表回答