EF4: Child reference in Parent Table. How?
If I have 2 tables:
Parent: Id (PK), ChildId (FK)
Child : Id (PK)
(Table names are not representative)
How do I get EF to create the tables s开发者_如何转开发o I can add a ChildId to the Parent table?
Everything I do, I get this created instead:
Parent: Id (PK)
Child : Id (PK), ParentId (FK)
I don't want that as the Child table will be updated independently and the values used in a dropdown list for the Parent to choose from.
I can do the hard stuff but the easy bits have me stumped!
R.
You say:
If I have 2 tables:
Then you say:
How do I get EF to create the tables..
That's a bit confusing. Are you generating the model from the database, doing model-first, code-first?
Based on "the 2 tables", EF should create two entities, "Parent" and "Child".
The cardinality will be: Child 1 - 1..* Parent.
There will be a navigational property on Parent called Child, and a navigational property called Parents (note pluralization) on Child.
Which doesn't really make sense.
I would think a Parent should have many Children.
I think you have your FK's the wrong way around. ParentID should be a FK on Child.
Make those changes, update your model then if you still have issues, paste a screenshot of your model and we'll go from there.
精彩评论