entity framework connection objects
-
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?
-
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?
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.
-
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.
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?
-
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?
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.