Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. entity framework connection objects

entity framework connection objects

Scheduled Pinned Locked Moved C#
databasesysadminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    George Nistor
    wrote on last edited by
    #1

    Hi How should be used these objects, - do I have to create an object every time in an using block (creating connection every time I need a query) or - I can create the object globally and reused for every query I need? Will the server close this connection if it is idle, and I will have an exception when trying to reuse it? Should be this object(context) thread safe?

    I 1 Reply Last reply
    0
    • G George Nistor

      Hi How should be used these objects, - do I have to create an object every time in an using block (creating connection every time I need a query) or - I can create the object globally and reused for every query I need? Will the server close this connection if it is idle, and I will have an exception when trying to reuse it? Should be this object(context) thread safe?

      I Offline
      I Offline
      Ingo
      wrote on last edited by
      #2

      George Nistor wrote:

      How should be used these objects,

      Which objects?

      George Nistor wrote:

      Will the server close this connection

      Are you talking about an SqlConnection? It will keep open a while, but I close the connection after the operations are done. I open it for the next time again.

      George Nistor wrote:

      Should be this object(context) thread safe?

      They are not thread-safe automatically. You have to use delegates to call them from different threads if you are talking about an sqlconnection. It would be more helpful if you say what you are talking about as concrete as possible. Otherwise I may have answered your questions but I think I don't have...

      ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

      G 1 Reply Last reply
      0
      • I Ingo

        George Nistor wrote:

        How should be used these objects,

        Which objects?

        George Nistor wrote:

        Will the server close this connection

        Are you talking about an SqlConnection? It will keep open a while, but I close the connection after the operations are done. I open it for the next time again.

        George Nistor wrote:

        Should be this object(context) thread safe?

        They are not thread-safe automatically. You have to use delegates to call them from different threads if you are talking about an sqlconnection. It would be more helpful if you say what you are talking about as concrete as possible. Otherwise I may have answered your questions but I think I don't have...

        ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

        G Offline
        G Offline
        George Nistor
        wrote on last edited by
        #3

        yes, I talk about SQL connection. What do you mean by using delegates. To create some functions where I open the connection with using ? ans possibly pass some delegates with the functionality I require?

        I 1 Reply Last reply
        0
        • G George Nistor

          yes, I talk about SQL connection. What do you mean by using delegates. To create some functions where I open the connection with using ? ans possibly pass some delegates with the functionality I require?

          I Offline
          I Offline
          Ingo
          wrote on last edited by
          #4

          George Nistor wrote:

          What do you mean by using delegates. To create some functions where I open the connection with using ?

          Sorry, I didn't told the truth, I mixed it up with something completely different. The SqlConnection is threadsave. Therefore no delegates aren't needed. I used some other communication at the same time and this wasn't threadsafe, so delegates were needed. :rolleyes:

          ------------------------------ Author of Primary ROleplaying SysTem How do I take my coffee? Black as midnight on a moonless night. War doesn't determine who's right. War determines who's left.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups