c# - Entity Framework Code First POCOs and reasons why / why not setup relationships? -
i wasn’t sure how word question , may change based on feedback.
when idea have reference relationships (in pocos) setup can parent record child or reverse? practice have way “reverse” lookup item or collection of items? know depends on application, want make sure of before start molding application. so, let’s have 2 tables: states , countries. states has relationship countries (many-to-one) , vice-versa (one-to- many). class state have property country , country class property collection of states. pretty standard.
in example may make sense allow country lookup associated states. can think of time may not care association don’t have overhead of loading items collection or single item?
it more design decission of entities. if using code first need navigation property on @ least 1 side create relation in database. can start simple approach , define property on side make sense , add other side if need somewhere.
there situations know never work child entity without parent (it leads theory aggregation roots whre child entity can't exist without parent). in such case child doesn't need have navigation property parent.
in scenario expect work state without country belongs to? if yes probable know states country contains in same time know country state belongs defining navigation property on both sides make sense.
Comments
Post a Comment