Silverlight - LinqToEntities - How to return anonymous types

I'm not sure if I will go right. I have a Silverlight application and I am using the Entity Framework for this. I have two entities mapped to my database: header and details. I want to send a connection with a left background to get all headers and details, even if the header record does not contain detailed records. Here is the Linq query that I want to run from the client:

var query = from head in storeContext.Headers join detail in storeContext.Details on head.HeadId equals details.HeadId into group select new { Desc = head.Description, MyCount = group.Count() }; 

Since this is Silverlight, I need to build my request and then send it to the server using the storeContext.Load<T>() method from my domain service (Context on the client). Since this method expects a type, I don't know how to structure the call to return an anonymous type, since I dong above?

Am I doing all this wrong? Should I use the Invoke method for something like this? If so, how and where to determine the type that I want to return?

Someone can point me in the right direction, I would really appreciate it.

Thanks ... Scott

0
c # anonymous-types linq-to-entities silverlight entity-framework
source share
2 answers

You cannot return an anonymous type. They, if necessary, are local to the current volume.

Your request looks correct, but you will need to return a named type:

 var query = from head in storeContext.Headers join detail in storeContext.Details on head.HeadId equals details.HeadId into group select new MyHelper // SPECIFY A CLASS HERE { Desc = head.Description, MyCount = group.Count() }; 

In your request method, you need to return IEnumerable<MyHelper> :

 public IEnumerable<MyHelper> GetInfo() { var query ... return query; } 
+5
source share

You can never return a value that is an instance of an anonymous type from a method. Anonymous types are always local to the method. If you want to return a type on top of WCF, you will have to write the class yourself, rather than relying on anonymous types.

+1
source share

All Articles