Wcf service returning linq object

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
keeper
Posts: 17
Joined: Mon 27 Dec 2010 09:20

Wcf service returning linq object

Post by keeper » Thu 03 Feb 2011 13:30

I'm trying to create a wcf service that returns a linq-mapped object.
I have a table "Users" mapped with linq as "User" and a table "Groups" mapped to "Group".
Groups has a many-to-many with Users and with itself.
When I try to return the linq object explicitely like this:

Code: Select all

User result = context.Users.Where(u => u.Id == 1);
return user;
the client gets disconnected from the wcf service with error 10054 : "An existing connection was forcibly closed by the remote host".
If I try to return a simple string in my service it works.
Is there a problem returning a linq object this way?
Since this worked for EF I think this should work too.

EDIT: I also read about setting Serialization Mode=Unidirectional but when I set it the code generated is checking for a bool property "serializing" which doesn't exists in my User class.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 07 Feb 2011 15:27

Thank you for the report, we have reproduced the issue. We will inform you when this error is fixed.

The problem is that the 'serializing' property is generated for one of the 'many-to-many' association sides only. As a temporary workaround, please try adding this property to another side as well, e.g.

Code: Select all

public partial class User : INotifyPropertyChanging, INotifyPropertyChanged    {
  ...
  private EntitySet _Groups;

  private bool serializing;
  ...
}
Please tell us if this helps.

keeper
Posts: 17
Joined: Mon 27 Dec 2010 09:20

Post by keeper » Tue 08 Feb 2011 08:42

Thanks, adding that missing property solved my problem.

Another question: is there a way to not serialize every EntitySet in a linq object? Since I'm going to have several relations within my objects, the data which are going to be serialized could be potentially huge.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 09 Feb 2011 16:06

Since LinqConnect uses deferred loading for associated entities, EntitySets should not be serialized by default. To enable serialization, it is necessary to define DataContext.LoadOptions in the WCF service method which retrieves the entity sequence.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 10 Feb 2011 17:49

We have fixed the error with the 'serializing' variable. The fix is available in the new 2.20.12 version of LinqConnect. This build can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial and free versions) and from Registered Users' Area (for users with active subscriptions only):
http://secure.devart.com/

For the information about other fixes and improvements available in LinqConnect 2.20.12, please refer to
http://www.devart.com/forums/viewtopic.php?t=20231

Post Reply