Print Page | Close Window

WCF and Idealblade

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3271
Printed Date: 12-Apr-2026 at 2:50pm


Topic: WCF and Idealblade
Posted By: hartdrooz
Subject: WCF and Idealblade
Date Posted: 17-Feb-2012 at 11:31am
Hi,

I created a WCF service, in this service I use idealblade to retrieve the data and send the entities to the client.

I have a class, this class have a constructor and in this constructor I create an instance of my entityManager (this is inside a private variable of the class).

After that the other methods use this private variable to do my queries.

The WCF service is by session so when the session is closed I do a disconnect to my private variable and I put it null.

So I open my client first time I retrieve data from a table it works without any problem.

I close my client, I open it again I do the same call and I got an error than I cannot run the query in this thread because it's use by another thread .....

I don't understand why ?

So I remove the private variable and create a variable inside each methods that do a call to the database in the WCF service and I don't have this error anymore.

But is not really a good pratice, I want to have a private variable inside the class and I was expecting no problem of threading because the client is closed etc...

Regards



Replies:
Posted By: sbelini
Date Posted: 21-Feb-2012 at 12:18pm
Hi hartdrooz,
 
Since your EntityManager was created in the first request, you wouldn't have a problem there because it was created and used in the same thread. For every subsequent request, most likely it will run a different thread and then the error you are getting.
If you are certain that there won't be more than 1 client connection at the same time, you could simply set
 
managerAuthorizeThreadId = null;
 
However, if there is more than one client request concurrently that uses the same EntityManager, you might face some unwanted behavior. In this case your best option is to set a new EntityManager for each request. (However, since your service is by session, you wouldn't run into this)
 
Regards,
   Silvio.



Print Page | Close Window