简体   繁体   中英

EF multiple contexts: read/write

my task is to have a component that allows persistent data reads/writes utilizing Entity Framework. Keeping in mind the following:

  • I do not care about 'written/updated' data should be immediately accessible for reading (or changes should be immediately available for reader);
  • I would like to turn off entities tracking when reading for performance sake;
  • Data reading and writing will run continuously;

So the question is: is this a good idea to have two separate contexts, that will live as long as components lives. One context is for write/update (with periodically SaveChanges call), another one is for reading (with entities tracking off).

Will I potentially gain benefits or on the contrary have issues with this approach?

Thanks in advance.

我认为这不是一个好主意,因为您将成为无法控制的数据模型的重复。

the recommended practice is to have shorter lived contexts, so they dont endup holding too many objects in memory and thus conflicting changes and complex relationships

this might help

http://blogs.msdn.com/b/dsimmons/archive/2008/03/02/more-about-how-to-fit-the-objectcontext-into-apps.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM