Why is “Fixup” needed for Persistence Ignorant POCO's in EF 4?

前端 未结 1 1174
醉酒成梦
醉酒成梦 2021-01-01 19:47

One of the much-anticipated features of Entity Framework 4 is the ability to use POCO (Plain Old CLR Objects) in a Persistence Ignorant manner (i.e. they don\'t \"know\" tha

相关标签:
1条回答
  • 2021-01-01 20:38

    Found a few explanations - check them out!

    POCO Template Code Generation Options (EF team blog)

    Fixup

    A fixup method is written for every navigation property on an entity and is called from the setter of the navigation property whenever its value changes. Its purpose is to ensure that each end of a bidirectional relationship stays in sync with the other. For example, in a one-to-many relationship between Cutomer and Order, whenever Order.Customer is set, the fixup method ensures that the Order is in the Customer’s Orders collection. It also keeps the corresponding foreign key property viz. Order.CustomerID in sync with the new Customer’s primary key (ID) value. This logic can be useful if the POCO entities are used independently of the EF stack, like for writing tests against them which don’t hit the database. Fixup ensures that the object graph is connected in the same way as you would expect while using them with EF. Fixup methods are a bit complex to write and hence it is useful to have them auto-generated if you are planning on using the entities in an EF independent scenario.

    And also check out this POCO in the Entity Framework Part 1 which also has some sections on what fixups are and what they're needed for.

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