Entity Framework 5 - Looking for Central Point to Execute Custom Code after Entity is Loaded from Database

前端 未结 2 573
盖世英雄少女心
盖世英雄少女心 2021-01-11 15:15

I am using Entity Framework 5 with Code First approach and using Fluent API for Entity configuration. My project has one particular Product Entity which gets half of its dat

2条回答
  •  天涯浪人
    2021-01-11 16:21

    1.) You can write your own EF Provider (but that is no small task)

    2.) You can attach items to the context but not save them.

    The entity.State can be set as Not modified after attaching. You could also remove such entries from Context prior to save changes

    3) You can Write a repository fascade that check EF and Checks location 2 and combines the result.

    On the question of navigation properties. You would need to specify these very carefully to avoid issues. Not lazy loaded or not even modelled.

    I wouldnt try and mix them personally.
    You can tell EF to ignore some properties. So you can have a Nice original POCO, but only model the bits that are on the DB.

    The POCO would then collect the rest.

    I use a fascade with events myself to act on KEY methods on a context/DBset. So I can trigger events on attach , get, save etc.

    good luck

提交回复
热议问题