Results 1 to 3 of 3

Thread: [RESOLVED] Entity Framework and threading

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Resolved [RESOLVED] Entity Framework and threading

    Hi Folks

    Im just getting started with EF (with SQL server) and threading.

    My question is about how I should access the context for threads that work with the context?

    Should I create a new context per thread or create one and lock on it from each thread that needs to use the context?

    Thanks
    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Entity Framework and threading

    If you create multiple contexts then you will have multiple versions of the same data and that's a bad thing. An EF context is just like any other data. You wouldn't create multiple arrays or collections to be used in multiple threads so it doesn't make sense to create multiple EF contexts. If you are going to synchronise access between threads though, don't use the context itself. It's always good practice to create an object solely for the purposes of locking.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    Re: [RESOLVED] Entity Framework and threading

    Thanks Jn
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width