How to extend Entities data context's ObjectSet
I want to implement a sort of preview mechanism for my application. I have few different models that can开发者_运维问答 be edited. On the edit page's I would like to provide a preview button that would put the edited model into session.
I am thinking maybe I could extend the ObjectSet properties to have it run queries through my in session objects on top of the regular objects in the database. I dont know if that is actually possible, but can anyone think of a way to make something like this happen?
It sounds like you would need a Repository / Unit of work layer that is independent of where the data is coming from, in the "Session" case it could come from in-memory objects stored in the current session, in the regular case from your DB Entity context. You could then pass in the actual data store handling (in memory or DB) as a dependency.
There are many samples around that do work with EF, mostly for the sake of unit testing w/o having to touch the DB:
- Testability and Entity Framework 4.0
- Creating a Generic Entity Framework 4.0 Repository
- Entity Framework 4 POCO, Repository and Specification Pattern
精彩评论