1

Why does this not work:

[OperationContract]
public List<Category> DoWork()
{
    using(var db= new PDataContext())
    {
        return db.Categories.Select(x => x).ToList();
    }
}

I get a CommunicationException error: Not Found.

But this does:

[OperationContract]
public List<myCategory> DoWork()
{
    using(var db= new PDataContext())
    {
        return  db.Categories.Select(x => new myCategory
                {
                  CategoryID = x.CategoryID,
                  Name = x.Name,
                  Visible = x.Visible,
                  ParentID = x.ParentID
                 }).ToList(); 
    }
 }

 public class myCategory
 {
     public int CategoryID { get; set; }
     public string Name { get; set; }
     public bool Visible { get; set; }
     public int ParentID { get; set; }
 }

I'm failing to understand how the LINQ2SQL Category class is in any way different than the code I wrote in the example above.

2
  • Is that an over-simplified example? Why do you have .Select(x => x) -- that doesn't do anything. Perhaps something is getting tripped up because of that. Commented Jun 18, 2011 at 1:58
  • An overlooked mistake. Removing it has no effect. Commented Jun 18, 2011 at 1:59

2 Answers 2

1

The only thing I can think is that you are causing an exception, relating to serialization, in your service by using the Linq2SQL class. Can you explain a little more about what type of relationships you have?

See this blog for what I think is a similar issue Returning LINQ to SQL Entities

Sign up to request clarification or add additional context in comments.

1 Comment

Changing the Serialization mode fixed it.
0

This does not work because the Category data object cannot be serialized over the wire.

You can find a more elaborate discussion here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.